goto out_bad;
/* The sysfs dirent has been moved to a different namespace */
- if (sd->s_parent && (sd->s_parent->s_flags & SYSFS_FLAG_NS) &&
+ if (sd->s_parent && kernfs_ns_enabled(sd->s_parent) &&
sysfs_info(dentry->d_sb)->ns != sd->s_ns)
goto out_bad;
int sysfs_add_one(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd,
struct sysfs_dirent *parent_sd)
{
- bool has_ns = parent_sd->s_flags & SYSFS_FLAG_NS;
+ bool has_ns = kernfs_ns_enabled(parent_sd);
struct sysfs_inode_attrs *ps_iattr;
int ret;
const void *ns)
{
struct rb_node *node = parent->s_dir.children.rb_node;
- bool has_ns = parent->s_flags & SYSFS_FLAG_NS;
+ bool has_ns = kernfs_ns_enabled(parent);
unsigned int hash;
lockdep_assert_held(&sysfs_mutex);
mutex_lock(&sysfs_mutex);
- if (parent_sd->s_flags & SYSFS_FLAG_NS)
+ if (kernfs_ns_enabled(parent_sd))
ns = sysfs_info(dir->i_sb)->ns;
sd = kernfs_find_ns(parent_sd, dentry->d_name.name, ns);
return 0;
mutex_lock(&sysfs_mutex);
- if (parent_sd->s_flags & SYSFS_FLAG_NS)
+ if (kernfs_ns_enabled(parent_sd))
ns = sysfs_info(dentry->d_sb)->ns;
for (pos = sysfs_dir_pos(ns, parent_sd, ctx->pos, pos);
* sysfs_remove_dir() for details.
*/
spin_lock(&sysfs_symlink_target_lock);
- if (targ->sd && (kobj->sd->s_flags & SYSFS_FLAG_NS))
+ if (targ->sd && kernfs_ns_enabled(kobj->sd))
ns = targ->sd->s_ns;
spin_unlock(&sysfs_symlink_target_lock);
kernfs_remove_by_name_ns(kobj->sd, name, ns);
sd->s_flags |= SYSFS_FLAG_NS;
}
+/**
+ * kernfs_ns_enabled - test whether namespace is enabled
+ * @sd: the node to test
+ *
+ * Test whether namespace filtering is enabled for the children of @ns.
+ */
+static inline bool kernfs_ns_enabled(struct sysfs_dirent *sd)
+{
+ return sd->s_flags & SYSFS_FLAG_NS;
+}
+
struct sysfs_dirent *kernfs_find_and_get_ns(struct sysfs_dirent *parent,
const char *name, const void *ns);
void kernfs_get(struct sysfs_dirent *sd);
static inline void kernfs_enable_ns(struct sysfs_dirent *sd) { }
+static inline bool kernfs_ns_enabled(struct sysfs_dirent *sd)
+{ return false; }
+
static inline struct sysfs_dirent *
kernfs_find_and_get_ns(struct sysfs_dirent *parent, const char *name,
const void *ns)