aboutsummaryrefslogtreecommitdiff
path: root/fs/sysfs/dir.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@woody.osdl.org>2006-12-01 16:41:07 -0800
committerLinus Torvalds <torvalds@woody.osdl.org>2006-12-01 16:41:07 -0800
commit4549df891a31b9a05b7d183106c09049b79327be (patch)
treed4dfd0921f0dd0dba2525fd33c0962b26ba5ff1e /fs/sysfs/dir.c
parent6b8cc71ab2619a776b02869fd733ac1ead3db4e8 (diff)
parente17e0f51aeea4e59c7e450a1c0f26605b91c1260 (diff)
Merge master.kernel.org:/pub/scm/linux/kernel/git/gregkh/driver-2.6
* master.kernel.org:/pub/scm/linux/kernel/git/gregkh/driver-2.6: (36 commits) Driver core: show drivers in /sys/module/ Documentation/driver-model/platform.txt update/rewrite Driver core: platform_driver_probe(), can save codespace driver core: Use klist_remove() in device_move() driver core: Introduce device_move(): move a device to a new parent. Driver core: make drivers/base/core.c:setup_parent() static driver core: Introduce device_find_child(). sysfs: sysfs_write_file() writes zero terminated data cpu topology: consider sysfs_create_group return value Driver core: Call platform_notify_remove later ACPI: Change ACPI to use dev_archdata instead of firmware_data Driver core: add dev_archdata to struct device Driver core: convert sound core to use struct device Driver core: change mem class_devices to be real devices Driver core: convert fb code to use struct device Driver core: convert firmware code to use struct device Driver core: convert mmc code to use struct device Driver core: convert ppdev code to use struct device Driver core: convert PPP code to use struct device Driver core: convert cpuid code to use struct device ...
Diffstat (limited to 'fs/sysfs/dir.c')
-rw-r--r--fs/sysfs/dir.c45
1 files changed, 45 insertions, 0 deletions
diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
index 3aa3434621c..a5782e8c7f0 100644
--- a/fs/sysfs/dir.c
+++ b/fs/sysfs/dir.c
@@ -372,6 +372,51 @@ int sysfs_rename_dir(struct kobject * kobj, const char *new_name)
return error;
}
+int sysfs_move_dir(struct kobject *kobj, struct kobject *new_parent)
+{
+ struct dentry *old_parent_dentry, *new_parent_dentry, *new_dentry;
+ struct sysfs_dirent *new_parent_sd, *sd;
+ int error;
+
+ if (!new_parent)
+ return -EINVAL;
+
+ old_parent_dentry = kobj->parent ?
+ kobj->parent->dentry : sysfs_mount->mnt_sb->s_root;
+ new_parent_dentry = new_parent->dentry;
+
+again:
+ mutex_lock(&old_parent_dentry->d_inode->i_mutex);
+ if (!mutex_trylock(&new_parent_dentry->d_inode->i_mutex)) {
+ mutex_unlock(&old_parent_dentry->d_inode->i_mutex);
+ goto again;
+ }
+
+ new_parent_sd = new_parent_dentry->d_fsdata;
+ sd = kobj->dentry->d_fsdata;
+
+ new_dentry = lookup_one_len(kobj->name, new_parent_dentry,
+ strlen(kobj->name));
+ if (IS_ERR(new_dentry)) {
+ error = PTR_ERR(new_dentry);
+ goto out;
+ } else
+ error = 0;
+ d_add(new_dentry, NULL);
+ d_move(kobj->dentry, new_dentry);
+ dput(new_dentry);
+
+ /* Remove from old parent's list and insert into new parent's list. */
+ list_del_init(&sd->s_sibling);
+ list_add(&sd->s_sibling, &new_parent_sd->s_children);
+
+out:
+ mutex_unlock(&new_parent_dentry->d_inode->i_mutex);
+ mutex_unlock(&old_parent_dentry->d_inode->i_mutex);
+
+ return error;
+}
+
static int sysfs_dir_open(struct inode *inode, struct file *file)
{
struct dentry * dentry = file->f_dentry;