Skip to content

Commit c984f4d

Browse files
KAGA-KOKOgregkh
authored andcommitted
scsi: sysfs: Introduce sysfs_{un,}break_active_protection()
commit 2afc916 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 <bart.vanassche@wdc.com> Acked-by: Tejun Heo <tj@kernel.org> Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Cc: <stable@vger.kernel.org> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent d071004 commit c984f4d

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

fs/sysfs/file.c

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,50 @@ int sysfs_chmod_file(struct kobject *kobj, const struct attribute *attr,
407407
}
408408
EXPORT_SYMBOL_GPL(sysfs_chmod_file);
409409

410+
/**
411+
* sysfs_break_active_protection - break "active" protection
412+
* @kobj: The kernel object @attr is associated with.
413+
* @attr: The attribute to break the "active" protection for.
414+
*
415+
* With sysfs, just like kernfs, deletion of an attribute is postponed until
416+
* all active .show() and .store() callbacks have finished unless this function
417+
* is called. Hence this function is useful in methods that implement self
418+
* deletion.
419+
*/
420+
struct kernfs_node *sysfs_break_active_protection(struct kobject *kobj,
421+
const struct attribute *attr)
422+
{
423+
struct kernfs_node *kn;
424+
425+
kobject_get(kobj);
426+
kn = kernfs_find_and_get(kobj->sd, attr->name);
427+
if (kn)
428+
kernfs_break_active_protection(kn);
429+
return kn;
430+
}
431+
EXPORT_SYMBOL_GPL(sysfs_break_active_protection);
432+
433+
/**
434+
* sysfs_unbreak_active_protection - restore "active" protection
435+
* @kn: Pointer returned by sysfs_break_active_protection().
436+
*
437+
* Undo the effects of sysfs_break_active_protection(). Since this function
438+
* calls kernfs_put() on the kernfs node that corresponds to the 'attr'
439+
* argument passed to sysfs_break_active_protection() that attribute may have
440+
* been removed between the sysfs_break_active_protection() and
441+
* sysfs_unbreak_active_protection() calls, it is not safe to access @kn after
442+
* this function has returned.
443+
*/
444+
void sysfs_unbreak_active_protection(struct kernfs_node *kn)
445+
{
446+
struct kobject *kobj = kn->parent->priv;
447+
448+
kernfs_unbreak_active_protection(kn);
449+
kernfs_put(kn);
450+
kobject_put(kobj);
451+
}
452+
EXPORT_SYMBOL_GPL(sysfs_unbreak_active_protection);
453+
410454
/**
411455
* sysfs_remove_file_ns - remove an object attribute with a custom ns tag
412456
* @kobj: object we're acting for

include/linux/sysfs.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,9 @@ int __must_check sysfs_create_files(struct kobject *kobj,
239239
const struct attribute **attr);
240240
int __must_check sysfs_chmod_file(struct kobject *kobj,
241241
const struct attribute *attr, umode_t mode);
242+
struct kernfs_node *sysfs_break_active_protection(struct kobject *kobj,
243+
const struct attribute *attr);
244+
void sysfs_unbreak_active_protection(struct kernfs_node *kn);
242245
void sysfs_remove_file_ns(struct kobject *kobj, const struct attribute *attr,
243246
const void *ns);
244247
bool sysfs_remove_file_self(struct kobject *kobj, const struct attribute *attr);
@@ -352,6 +355,17 @@ static inline int sysfs_chmod_file(struct kobject *kobj,
352355
return 0;
353356
}
354357

358+
static inline struct kernfs_node *
359+
sysfs_break_active_protection(struct kobject *kobj,
360+
const struct attribute *attr)
361+
{
362+
return NULL;
363+
}
364+
365+
static inline void sysfs_unbreak_active_protection(struct kernfs_node *kn)
366+
{
367+
}
368+
355369
static inline void sysfs_remove_file_ns(struct kobject *kobj,
356370
const struct attribute *attr,
357371
const void *ns)

0 commit comments

Comments
 (0)