Skip to content

Commit 8f024a0

Browse files
KAGA-KOKOZhengShunQian
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 <[email protected]> Acked-by: Tejun Heo <[email protected]> Acked-by: Greg Kroah-Hartman <[email protected]> Cc: <[email protected]> Signed-off-by: Martin K. Petersen <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent db76d20 commit 8f024a0

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
@@ -238,6 +238,9 @@ int __must_check sysfs_create_files(struct kobject *kobj,
238238
const struct attribute **attr);
239239
int __must_check sysfs_chmod_file(struct kobject *kobj,
240240
const struct attribute *attr, umode_t mode);
241+
struct kernfs_node *sysfs_break_active_protection(struct kobject *kobj,
242+
const struct attribute *attr);
243+
void sysfs_unbreak_active_protection(struct kernfs_node *kn);
241244
void sysfs_remove_file_ns(struct kobject *kobj, const struct attribute *attr,
242245
const void *ns);
243246
bool sysfs_remove_file_self(struct kobject *kobj, const struct attribute *attr);
@@ -351,6 +354,17 @@ static inline int sysfs_chmod_file(struct kobject *kobj,
351354
return 0;
352355
}
353356

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

0 commit comments

Comments
 (0)