Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 350940
b: refs/heads/master
c: 0bb8f3d
h: refs/heads/master
v: v3
  • Loading branch information
Rafael J. Wysocki committed Jan 25, 2013
1 parent 80119ce commit b9de314
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 14 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: b1c0f99bfb89cd9b42e3119ab822a8102fa87909
refs/heads/master: 0bb8f3d6ae621945e6fa2102aa894f72b76a023e
42 changes: 42 additions & 0 deletions trunk/fs/sysfs/group.c
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,48 @@ void sysfs_unmerge_group(struct kobject *kobj,
}
EXPORT_SYMBOL_GPL(sysfs_unmerge_group);

/**
* sysfs_add_link_to_group - add a symlink to an attribute group.
* @kobj: The kobject containing the group.
* @group_name: The name of the group.
* @target: The target kobject of the symlink to create.
* @link_name: The name of the symlink to create.
*/
int sysfs_add_link_to_group(struct kobject *kobj, const char *group_name,
struct kobject *target, const char *link_name)
{
struct sysfs_dirent *dir_sd;
int error = 0;

dir_sd = sysfs_get_dirent(kobj->sd, NULL, group_name);
if (!dir_sd)
return -ENOENT;

error = sysfs_create_link_sd(dir_sd, target, link_name);
sysfs_put(dir_sd);

return error;
}
EXPORT_SYMBOL_GPL(sysfs_add_link_to_group);

/**
* sysfs_remove_link_from_group - remove a symlink from an attribute group.
* @kobj: The kobject containing the group.
* @group_name: The name of the group.
* @link_name: The name of the symlink to remove.
*/
void sysfs_remove_link_from_group(struct kobject *kobj, const char *group_name,
const char *link_name)
{
struct sysfs_dirent *dir_sd;

dir_sd = sysfs_get_dirent(kobj->sd, NULL, group_name);
if (dir_sd) {
sysfs_hash_and_remove(dir_sd, NULL, link_name);
sysfs_put(dir_sd);
}
}
EXPORT_SYMBOL_GPL(sysfs_remove_link_from_group);

EXPORT_SYMBOL_GPL(sysfs_create_group);
EXPORT_SYMBOL_GPL(sysfs_update_group);
Expand Down
45 changes: 32 additions & 13 deletions trunk/fs/sysfs/symlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,17 @@

#include "sysfs.h"

static int sysfs_do_create_link(struct kobject *kobj, struct kobject *target,
const char *name, int warn)
static int sysfs_do_create_link_sd(struct sysfs_dirent *parent_sd,
struct kobject *target,
const char *name, int warn)
{
struct sysfs_dirent *parent_sd = NULL;
struct sysfs_dirent *target_sd = NULL;
struct sysfs_dirent *sd = NULL;
struct sysfs_addrm_cxt acxt;
enum kobj_ns_type ns_type;
int error;

BUG_ON(!name);

if (!kobj)
parent_sd = &sysfs_root;
else
parent_sd = kobj->sd;

error = -EFAULT;
if (!parent_sd)
goto out_put;
BUG_ON(!name || !parent_sd);

/* target->sd can go away beneath us but is protected with
* sysfs_assoc_lock. Fetch target_sd from it.
Expand Down Expand Up @@ -95,6 +86,34 @@ static int sysfs_do_create_link(struct kobject *kobj, struct kobject *target,
return error;
}

/**
* sysfs_create_link_sd - create symlink to a given object.
* @sd: directory we're creating the link in.
* @target: object we're pointing to.
* @name: name of the symlink.
*/
int sysfs_create_link_sd(struct sysfs_dirent *sd, struct kobject *target,
const char *name)
{
return sysfs_do_create_link_sd(sd, target, name, 1);
}

static int sysfs_do_create_link(struct kobject *kobj, struct kobject *target,
const char *name, int warn)
{
struct sysfs_dirent *parent_sd = NULL;

if (!kobj)
parent_sd = &sysfs_root;
else
parent_sd = kobj->sd;

if (!parent_sd)
return -EFAULT;

return sysfs_do_create_link_sd(parent_sd, target, name, warn);
}

/**
* sysfs_create_link - create symlink between two objects.
* @kobj: object whose directory we're creating the link in.
Expand Down
2 changes: 2 additions & 0 deletions trunk/fs/sysfs/sysfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -240,3 +240,5 @@ void unmap_bin_file(struct sysfs_dirent *attr_sd);
* symlink.c
*/
extern const struct inode_operations sysfs_symlink_inode_operations;
int sysfs_create_link_sd(struct sysfs_dirent *sd, struct kobject *target,
const char *name);
16 changes: 16 additions & 0 deletions trunk/include/linux/sysfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,10 @@ int sysfs_merge_group(struct kobject *kobj,
const struct attribute_group *grp);
void sysfs_unmerge_group(struct kobject *kobj,
const struct attribute_group *grp);
int sysfs_add_link_to_group(struct kobject *kobj, const char *group_name,
struct kobject *target, const char *link_name);
void sysfs_remove_link_from_group(struct kobject *kobj, const char *group_name,
const char *link_name);

void sysfs_notify(struct kobject *kobj, const char *dir, const char *attr);
void sysfs_notify_dirent(struct sysfs_dirent *sd);
Expand Down Expand Up @@ -326,6 +330,18 @@ static inline void sysfs_unmerge_group(struct kobject *kobj,
{
}

static inline int sysfs_add_link_to_group(struct kobject *kobj,
const char *group_name, struct kobject *target,
const char *link_name)
{
return 0;
}

static inline void sysfs_remove_link_from_group(struct kobject *kobj,
const char *group_name, const char *link_name)
{
}

static inline void sysfs_notify(struct kobject *kobj, const char *dir,
const char *attr)
{
Expand Down

0 comments on commit b9de314

Please sign in to comment.