Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 266868
b: refs/heads/master
c: 487505c
h: refs/heads/master
v: v3
  • Loading branch information
Eric W. Biederman authored and David S. Miller committed Oct 19, 2011
1 parent 7c77f54 commit 9473f62
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 3 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: d5edf2906e0a251ddddd76caeb1b79de8bb5e3b8
refs/heads/master: 487505c257021fc06a7d05753cf27b011487f1dc
53 changes: 51 additions & 2 deletions trunk/fs/sysfs/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -488,17 +488,56 @@ const struct file_operations sysfs_file_operations = {
.poll = sysfs_poll,
};

int sysfs_attr_ns(struct kobject *kobj, const struct attribute *attr,
const void **pns)
{
struct sysfs_dirent *dir_sd = kobj->sd;
const struct sysfs_ops *ops;
const void *ns = NULL;
int err;

err = 0;
if (!sysfs_ns_type(dir_sd))
goto out;

err = -EINVAL;
if (!kobj->ktype)
goto out;
ops = kobj->ktype->sysfs_ops;
if (!ops)
goto out;
if (!ops->namespace)
goto out;

err = 0;
ns = ops->namespace(kobj, attr);
out:
if (err) {
WARN(1, KERN_ERR "missing sysfs namespace attribute operation for "
"kobject: %s\n", kobject_name(kobj));
}
*pns = ns;
return err;
}

int sysfs_add_file_mode(struct sysfs_dirent *dir_sd,
const struct attribute *attr, int type, mode_t amode)
{
umode_t mode = (amode & S_IALLUGO) | S_IFREG;
struct sysfs_addrm_cxt acxt;
struct sysfs_dirent *sd;
const void *ns;
int rc;

rc = sysfs_attr_ns(dir_sd->s_dir.kobj, attr, &ns);
if (rc)
return rc;

sd = sysfs_new_dirent(attr->name, mode, type);
if (!sd)
return -ENOMEM;

sd->s_ns = ns;
sd->s_attr.attr = (void *)attr;
sysfs_dirent_init_lockdep(sd);

Expand Down Expand Up @@ -586,12 +625,17 @@ int sysfs_chmod_file(struct kobject *kobj, const struct attribute *attr,
{
struct sysfs_dirent *sd;
struct iattr newattrs;
const void *ns;
int rc;

rc = sysfs_attr_ns(kobj, attr, &ns);
if (rc)
return rc;

mutex_lock(&sysfs_mutex);

rc = -ENOENT;
sd = sysfs_find_dirent(kobj->sd, NULL, attr->name);
sd = sysfs_find_dirent(kobj->sd, ns, attr->name);
if (!sd)
goto out;

Expand All @@ -616,7 +660,12 @@ EXPORT_SYMBOL_GPL(sysfs_chmod_file);

void sysfs_remove_file(struct kobject * kobj, const struct attribute * attr)
{
sysfs_hash_and_remove(kobj->sd, NULL, attr->name);
const void *ns;

if (sysfs_attr_ns(kobj, attr, &ns))
return;

sysfs_hash_and_remove(kobj->sd, ns, attr->name);
}

void sysfs_remove_files(struct kobject * kobj, const struct attribute **ptr)
Expand Down
1 change: 1 addition & 0 deletions trunk/include/linux/sysfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ struct bin_attribute {
struct sysfs_ops {
ssize_t (*show)(struct kobject *, struct attribute *,char *);
ssize_t (*store)(struct kobject *,struct attribute *,const char *, size_t);
const void *(*namespace)(struct kobject *, const struct attribute *);
};

struct sysfs_dirent;
Expand Down

0 comments on commit 9473f62

Please sign in to comment.