Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2990663imu; Sun, 9 Dec 2018 14:28:22 -0800 (PST) X-Google-Smtp-Source: AFSGD/Wi7zDu/FVhBGJzD868ge1lnAC+mN2t78UiBkIqbaUwkGBDLi8VZRL76Sgh5xolrGYUwB+8 X-Received: by 2002:a17:902:b118:: with SMTP id q24mr10048480plr.209.1544394502055; Sun, 09 Dec 2018 14:28:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544394502; cv=none; d=google.com; s=arc-20160816; b=kAuWPCFvnoMNmvbThS3AxBJ+Ii3i8aDbIrGZRmjSwtO4D3ZIln3W8F3/KWTn+lZ7wg jchv0byNOJ4/01d76R4ZhKhJIqdBGER5u+YAPH/kpjPVVSrv92pwy8FF+MtZ2gQsPcqK IO7OYGZVjhCqqwjGc0R+D+gDuyJbeWPZAiC2LQO6yC9wtd/3GL4c6zErzr11Knj3kdpt hjpqC7w3oMicJeex/KpGyb4sl9Qij/uk5v8b47fo3jHiBWPjDCfS21EFJkHHSfIS4xjk F8EDCAU31LNSRgY6yucQMN1atTHDbXeMwBdnWM6s8MWv4xHWCEKGVtChHY+He1VRNu4h 8I0w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition; bh=OECPpWou9K9f2shkXJZh4vkJ9e8MVUoXZJnJZpLWDRQ=; b=SaPkCKKUtV0+aWn9sbh0BWvoFjggR6AST08Mn7FDEkociDsIEhhtG1xDGVifwfx9WU ynNgAKxHR5BoRnVzQ2JvSXeIhofFSVt2dBcGnGD0H3a84eHD7O9SzCHJOi8ItfC+07ub 1pWVb4PMJQL8wgrPRpu2cIihrqB7FcraPmCrkdkzYpnf9T9ozfE0h/p5WSbx9LvmVV4E 22g7c7w3WGUO2BcdE6/wotDVKJebcak1PNUk9kkFnHSA3rAUtivykp2hkwFpIBFgNUE0 qrZnIHvt09ECfx7h1gNG9HyzyCm6USAP3EWS+j/hmdPNPZzT3UiimwhAQTHnqBjyWRAe m17Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c19si8050137pls.242.2018.12.09.14.28.07; Sun, 09 Dec 2018 14:28:22 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728747AbeLIWZh (ORCPT + 99 others); Sun, 9 Dec 2018 17:25:37 -0500 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:34888 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726442AbeLIVzP (ORCPT ); Sun, 9 Dec 2018 16:55:15 -0500 Received: from pub.yeoldevic.com ([81.174.156.145] helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1gW72e-0002if-E5; Sun, 09 Dec 2018 21:55:12 +0000 Received: from ben by deadeye with local (Exim 4.91) (envelope-from ) id 1gW72b-0003Ks-MI; Sun, 09 Dec 2018 21:55:09 +0000 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, "Tejun Heo" , "Martin K. Petersen" , "Bart Van Assche" , "Greg Kroah-Hartman" Date: Sun, 09 Dec 2018 21:50:33 +0000 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) X-Patchwork-Hint: ignore Subject: [PATCH 3.16 096/328] scsi: sysfs: Introduce sysfs_{un,}break_active_protection() In-Reply-To: X-SA-Exim-Connect-IP: 81.174.156.145 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.62-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: Bart Van Assche commit 2afc9166f79b8f6da5f347f48515215ceee4ae37 upstream. Introduce these two functions and export them such that the next patch can add calls to these functions from the SCSI core. Signed-off-by: Bart Van Assche Acked-by: Tejun Heo Acked-by: Greg Kroah-Hartman Signed-off-by: Martin K. Petersen Signed-off-by: Ben Hutchings --- fs/sysfs/file.c | 44 +++++++++++++++++++++++++++++++++++++++++++ include/linux/sysfs.h | 14 ++++++++++++++ 2 files changed, 58 insertions(+) --- a/fs/sysfs/file.c +++ b/fs/sysfs/file.c @@ -357,6 +357,50 @@ int sysfs_chmod_file(struct kobject *kob EXPORT_SYMBOL_GPL(sysfs_chmod_file); /** + * sysfs_break_active_protection - break "active" protection + * @kobj: The kernel object @attr is associated with. + * @attr: The attribute to break the "active" protection for. + * + * With sysfs, just like kernfs, deletion of an attribute is postponed until + * all active .show() and .store() callbacks have finished unless this function + * is called. Hence this function is useful in methods that implement self + * deletion. + */ +struct kernfs_node *sysfs_break_active_protection(struct kobject *kobj, + const struct attribute *attr) +{ + struct kernfs_node *kn; + + kobject_get(kobj); + kn = kernfs_find_and_get(kobj->sd, attr->name); + if (kn) + kernfs_break_active_protection(kn); + return kn; +} +EXPORT_SYMBOL_GPL(sysfs_break_active_protection); + +/** + * sysfs_unbreak_active_protection - restore "active" protection + * @kn: Pointer returned by sysfs_break_active_protection(). + * + * Undo the effects of sysfs_break_active_protection(). Since this function + * calls kernfs_put() on the kernfs node that corresponds to the 'attr' + * argument passed to sysfs_break_active_protection() that attribute may have + * been removed between the sysfs_break_active_protection() and + * sysfs_unbreak_active_protection() calls, it is not safe to access @kn after + * this function has returned. + */ +void sysfs_unbreak_active_protection(struct kernfs_node *kn) +{ + struct kobject *kobj = kn->parent->priv; + + kernfs_unbreak_active_protection(kn); + kernfs_put(kn); + kobject_put(kobj); +} +EXPORT_SYMBOL_GPL(sysfs_unbreak_active_protection); + +/** * sysfs_remove_file_ns - remove an object attribute with a custom ns tag * @kobj: object we're acting for * @attr: attribute descriptor --- a/include/linux/sysfs.h +++ b/include/linux/sysfs.h @@ -204,6 +204,9 @@ int __must_check sysfs_create_files(stru const struct attribute **attr); int __must_check sysfs_chmod_file(struct kobject *kobj, const struct attribute *attr, umode_t mode); +struct kernfs_node *sysfs_break_active_protection(struct kobject *kobj, + const struct attribute *attr); +void sysfs_unbreak_active_protection(struct kernfs_node *kn); void sysfs_remove_file_ns(struct kobject *kobj, const struct attribute *attr, const void *ns); bool sysfs_remove_file_self(struct kobject *kobj, const struct attribute *attr); @@ -314,6 +317,17 @@ static inline int sysfs_chmod_file(struc return 0; } +static inline struct kernfs_node * +sysfs_break_active_protection(struct kobject *kobj, + const struct attribute *attr) +{ + return NULL; +} + +static inline void sysfs_unbreak_active_protection(struct kernfs_node *kn) +{ +} + static inline void sysfs_remove_file_ns(struct kobject *kobj, const struct attribute *attr, const void *ns)