bk://kernel.bkbits.net/gregkh/linux/driver-2.6
rene.herman@keyaccess.nl|ChangeSet|20040518002858|37409 rene.herman

# This is a BitKeeper generated diff -Nru style patch.
#
# fs/sysfs/dir.c
#   2004/05/17 03:47:17-07:00 maneesh@in.ibm.com +11 -1
#   fix-sysfs-symlinks.patch
# 
# ChangeSet
#   2004/05/22 23:30:58-07:00 akpm@bix.(none) 
#   Merge bix.(none):/usr/src/bk25 into bix.(none):/usr/src/bk-driver-core
# 
# drivers/char/vt.c
#   2004/05/22 23:30:55-07:00 akpm@bix.(none) +0 -0
#   Auto merged
# 
# ChangeSet
#   2004/05/21 18:51:42-07:00 akpm@bix.(none) 
#   Merge bix.(none):/usr/src/bk25 into bix.(none):/usr/src/bk-driver-core
# 
# drivers/video/fbmem.c
#   2004/05/21 18:51:39-07:00 akpm@bix.(none) +0 -0
#   Auto merged
# 
# ChangeSet
#   2004/05/20 21:46:58-07:00 akpm@bix.(none) 
#   Merge bix.(none):/usr/src/bk25 into bix.(none):/usr/src/bk-driver-core
# 
# drivers/video/fbmem.c
#   2004/05/20 21:46:55-07:00 akpm@bix.(none) +0 -0
#   Auto merged
# 
# ChangeSet
#   2004/05/17 17:28:58-07:00 rene.herman@keyaccess.nl 
#   [PATCH] missing closing \n in printk
# 
# drivers/firmware/smbios.c
#   2004/05/03 06:33:57-07:00 rene.herman@keyaccess.nl +1 -1
#   missing closing \n in printk
# 
# ChangeSet
#   2004/05/17 10:32:30-07:00 maneesh@in.ibm.com 
#   [PATCH] fix-sysfs-symlinks.patch
#   
#   - Rediffed the patch for 2.6.6-mm3 to fix rejects in the latest changes
#     in sysfs code.
#   
#   o The symlinks code in sysfs doesnot point to the correct target kobject
#     whenever target kobject is renamed and suffers from dangling symlinks
#     if target kobject is removed.
#   
#   o The following patch implements ->readlink and ->follow_link operations
#     for sysfs instead of using the page_symlink_inode_operations.
#     The pointer to target kobject is saved in the link dentry's d_fsdata field.
#     The target path is generated everytime we do ->readlink and ->follow_link.
#     This results in generating the correct target path during readlink and
#     follow_link operations inspite of renamed target kobject.
#   
#   o This also pins the target kobject during link creation and the ref. is
#     released when the link is removed.
#   
#   o Apart from being correct this patch also saves some memory by not pinning
#     a whole page for saving the target information.
#   
#   o Used a rw_semaphor sysfs_rename_sem to avoid clashing with renaming of
#     ancestors while the target path is generated.
#   
#   o Used dcache_lock in fs/sysfs/sysfs.h:sysfs_get_kobject() because of using
#     d_drop() while removing dentries.
# 
# fs/sysfs/sysfs.h
#   2004/05/17 03:28:39-07:00 maneesh@in.ibm.com +5 -2
#   fix-sysfs-symlinks.patch
# 
# fs/sysfs/symlink.c
#   2004/05/17 03:34:09-07:00 maneesh@in.ibm.com +94 -41
#   fix-sysfs-symlinks.patch
# 
# fs/sysfs/inode.c
#   2004/05/17 03:46:44-07:00 maneesh@in.ibm.com +6 -1
#   fix-sysfs-symlinks.patch
# 
# ChangeSet
#   2004/05/16 01:36:03-07:00 akpm@bix.(none) 
#   Merge bix.(none):/usr/src/bk25 into bix.(none):/usr/src/bk-driver-core
# 
# kernel/module.c
#   2004/05/16 01:36:00-07:00 akpm@bix.(none) +0 -0
#   Auto merged
# 
# drivers/video/fbmem.c
#   2004/05/16 01:36:00-07:00 akpm@bix.(none) +0 -0
#   Auto merged
# 
# ChangeSet
#   2004/05/14 21:22:51-07:00 akpm@bix.(none) 
#   Merge bix.(none):/usr/src/bk25 into bix.(none):/usr/src/bk-driver-core
# 
# kernel/module.c
#   2004/05/14 21:22:48-07:00 akpm@bix.(none) +0 -0
#   Auto merged
# 
# drivers/firmware/Kconfig
#   2004/05/14 21:22:48-07:00 akpm@bix.(none) +0 -0
#   Auto merged
# 
# drivers/char/vt.c
#   2004/05/14 21:22:48-07:00 akpm@bix.(none) +0 -0
#   Auto merged
# 
# ChangeSet
#   2004/05/11 16:41:30-07:00 akpm@bix.(none) 
#   Merge bk://kernel.bkbits.net/gregkh/linux/driver-2.6
#   into bix.(none):/usr/src/bk-driver-core
# 
# kernel/module.c
#   2004/05/11 16:41:27-07:00 akpm@bix.(none) +0 -0
#   Auto merged
# 
# ChangeSet
#   2004/05/11 16:40:27-07:00 akpm@bix.(none) 
#   Merge bix.(none):/usr/src/bk25 into bix.(none):/usr/src/bk-driver-core
# 
# kernel/module.c
#   2004/05/11 16:40:24-07:00 akpm@bix.(none) +0 -0
#   Auto merged
# 
# drivers/video/fbmem.c
#   2004/05/11 16:40:24-07:00 akpm@bix.(none) +0 -0
#   Auto merged
# 
# drivers/firmware/Kconfig
#   2004/05/11 16:40:24-07:00 akpm@bix.(none) +0 -0
#   Auto merged
# 
# ChangeSet
#   2004/04/28 13:21:19-07:00 akpm@bix.(none) 
#   Merge bix.(none):/usr/src/bk25 into bix.(none):/usr/src/bk-driver-core
# 
# drivers/isdn/capi/capi.c
#   2004/04/28 13:21:16-07:00 akpm@bix.(none) +0 -0
#   Auto merged
# 
# ChangeSet
#   2004/04/26 18:13:55-07:00 akpm@bix.(none) 
#   Merge bix.(none):/usr/src/bk25 into bix.(none):/usr/src/bk-driver-core
# 
# drivers/isdn/capi/capi.c
#   2004/04/26 18:13:52-07:00 akpm@bix.(none) +0 -0
#   Auto merged
# 
# ChangeSet
#   2004/04/21 21:55:11-07:00 akpm@bix.(none) 
#   Merge bix.(none):/usr/src/bk25 into bix.(none):/usr/src/bk-driver-core
# 
# drivers/video/fbmem.c
#   2004/04/21 21:55:09-07:00 akpm@bix.(none) +0 -0
#   Auto merged
# 
# ChangeSet
#   2004/04/19 19:27:32-07:00 akpm@bix.(none) 
#   Merge bix.(none):/usr/src/bk25 into bix.(none):/usr/src/bk-driver-core
# 
# drivers/video/fbmem.c
#   2004/04/19 19:27:29-07:00 akpm@bix.(none) +0 -0
#   Auto merged
# 
# drivers/isdn/capi/capi.c
#   2004/04/19 19:27:29-07:00 akpm@bix.(none) +0 -0
#   Auto merged
# 
# drivers/char/vt.c
#   2004/04/19 19:27:29-07:00 akpm@bix.(none) +0 -0
#   Auto merged
# 
# ChangeSet
#   2004/04/09 13:19:25-07:00 akpm@bix.(none) 
#   Merge bk://kernel.bkbits.net/gregkh/linux/driver-2.6
#   into bix.(none):/usr/src/bk-driver-core
# 
# drivers/isdn/capi/capi.c
#   2004/04/09 13:19:23-07:00 akpm@bix.(none) +0 -0
#   Auto merged
# 
# ChangeSet
#   2004/03/31 12:15:48-08:00 akpm@bix.(none) 
#   Merge bix.(none):/usr/src/bk25 into bix.(none):/usr/src/bk-driver-core
# 
# drivers/char/vt.c
#   2004/03/31 12:15:46-08:00 akpm@bix.(none) +0 -0
#   Auto merged
# 
# ChangeSet
#   2004/03/26 12:12:33-08:00 akpm@bix.(none) 
#   Merge bix.(none):/usr/src/bk25 into bix.(none):/usr/src/bk-driver-core
# 
# drivers/video/fbmem.c
#   2004/03/26 12:12:31-08:00 akpm@bix.(none) +0 -0
#   Auto merged
# 
# drivers/char/vt.c
#   2004/03/26 12:12:31-08:00 akpm@bix.(none) +0 -0
#   Auto merged
# 
# ChangeSet
#   2004/03/24 02:37:20-08:00 akpm@bix.(none) 
#   Merge bix.(none):/usr/src/bk25 into bix.(none):/usr/src/bk-driver-core
# 
# drivers/video/fbmem.c
#   2004/03/24 02:37:18-08:00 akpm@bix.(none) +0 -0
#   Auto merged
# 
# ChangeSet
#   2004/03/20 13:16:54-08:00 akpm@bix.(none) 
#   Merge bix.(none):/usr/src/bk25 into bix.(none):/usr/src/bk-driver-core
# 
# drivers/char/vt.c
#   2004/03/20 13:16:51-08:00 akpm@bix.(none) +0 -0
#   Auto merged
# 
diff -Nru a/drivers/firmware/smbios.c b/drivers/firmware/smbios.c
--- a/drivers/firmware/smbios.c	2004-05-25 21:22:09 -07:00
+++ b/drivers/firmware/smbios.c	2004-05-25 21:22:09 -07:00
@@ -126,7 +126,7 @@
 	if(keep_going != 0)
 		printk(KERN_INFO "Warning: SMBIOS table does not end with a"
 				" structure type 127. This may indicate a"
-				" truncated table.");
+				" truncated table.\n");
 
 	if(sdev->smbios_table_real_length != max_length)
 		printk(KERN_INFO "Warning: BIOS specified SMBIOS table length"
diff -Nru a/fs/sysfs/dir.c b/fs/sysfs/dir.c
--- a/fs/sysfs/dir.c	2004-05-25 21:22:09 -07:00
+++ b/fs/sysfs/dir.c	2004-05-25 21:22:09 -07:00
@@ -10,6 +10,8 @@
 #include <linux/kobject.h>
 #include "sysfs.h"
 
+DECLARE_RWSEM(sysfs_rename_sem);
+
 static int init_dir(struct inode * inode)
 {
 	inode->i_op = &simple_dir_inode_operations;
@@ -134,8 +136,14 @@
 			/**
 			 * Unlink and unhash.
 			 */
+			__d_drop(d);
 			spin_unlock(&dcache_lock);
-			d_delete(d);
+			/* release the target kobject in case of 
+			 * a symlink
+			 */
+			if (S_ISLNK(d->d_inode->i_mode))
+				kobject_put(d->d_fsdata);
+			
 			simple_unlink(dentry->d_inode,d);
 			dput(d);
 			pr_debug(" done\n");
@@ -165,6 +173,7 @@
 	if (!kobj->parent)
 		return -EINVAL;
 
+	down_write(&sysfs_rename_sem);
 	parent = kobj->parent->dentry;
 
 	down(&parent->d_inode->i_sem);
@@ -179,6 +188,7 @@
 		dput(new_dentry);
 	}
 	up(&parent->d_inode->i_sem);	
+	up_write(&sysfs_rename_sem);
 
 	return error;
 }
diff -Nru a/fs/sysfs/inode.c b/fs/sysfs/inode.c
--- a/fs/sysfs/inode.c	2004-05-25 21:22:09 -07:00
+++ b/fs/sysfs/inode.c	2004-05-25 21:22:09 -07:00
@@ -96,7 +96,12 @@
 			pr_debug("sysfs: Removing %s (%d)\n", victim->d_name.name,
 				 atomic_read(&victim->d_count));
 
-			d_delete(victim);
+			d_drop(victim);
+			/* release the target kobject in case of 
+			 * a symlink
+			 */
+			if (S_ISLNK(victim->d_inode->i_mode))
+				kobject_put(victim->d_fsdata);
 			simple_unlink(dir->d_inode,victim);
 		}
 		/*
diff -Nru a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
--- a/fs/sysfs/symlink.c	2004-05-25 21:22:09 -07:00
+++ b/fs/sysfs/symlink.c	2004-05-25 21:22:09 -07:00
@@ -8,27 +8,17 @@
 
 #include "sysfs.h"
 
+static struct inode_operations sysfs_symlink_inode_operations = {
+	.readlink = sysfs_readlink,
+	.follow_link = sysfs_follow_link,
+};
 
 static int init_symlink(struct inode * inode)
 {
-	inode->i_op = &page_symlink_inode_operations;
+	inode->i_op = &sysfs_symlink_inode_operations;
 	return 0;
 }
 
-static int sysfs_symlink(struct inode * dir, struct dentry *dentry, const char * symname)
-{
-	int error;
-
-	error = sysfs_create(dentry, S_IFLNK|S_IRWXUGO, init_symlink);
-	if (!error) {
-		int l = strlen(symname)+1;
-		error = page_symlink(dentry->d_inode, symname, l);
-		if (error)
-			iput(dentry->d_inode);
-	}
-	return error;
-}
-
 static int object_depth(struct kobject * kobj)
 {
 	struct kobject * p = kobj;
@@ -74,37 +64,20 @@
 	struct dentry * dentry = kobj->dentry;
 	struct dentry * d;
 	int error = 0;
-	int size;
-	int depth;
-	char * path;
-	char * s;
-
-	depth = object_depth(kobj);
-	size = object_path_length(target) + depth * 3 - 1;
-	if (size > PATH_MAX)
-		return -ENAMETOOLONG;
-	pr_debug("%s: depth = %d, size = %d\n",__FUNCTION__,depth,size);
-
-	path = kmalloc(size,GFP_KERNEL);
-	if (!path)
-		return -ENOMEM;
-	memset(path,0,size);
-
-	for (s = path; depth--; s += 3)
-		strcpy(s,"../");
-
-	fill_object_path(target,path,size);
-	pr_debug("%s: path = '%s'\n",__FUNCTION__,path);
 
 	down(&dentry->d_inode->i_sem);
 	d = sysfs_get_dentry(dentry,name);
-	if (!IS_ERR(d))
-		error = sysfs_symlink(dentry->d_inode,d,path);
-	else
+	if (!IS_ERR(d)) {
+		error = sysfs_create(d, S_IFLNK|S_IRWXUGO, init_symlink);
+		if (!error)
+			/* 
+			 * associate the link dentry with the target kobject 
+			 */
+			d->d_fsdata = kobject_get(target);
+		dput(d);
+	} else 
 		error = PTR_ERR(d);
-	dput(d);
 	up(&dentry->d_inode->i_sem);
-	kfree(path);
 	return error;
 }
 
@@ -120,6 +93,86 @@
 	sysfs_hash_and_remove(kobj->dentry,name);
 }
 
+static int sysfs_get_target_path(struct kobject * kobj, struct kobject * target,
+				   char *path)
+{
+	char * s;
+	int depth, size;
+
+	depth = object_depth(kobj);
+	size = object_path_length(target) + depth * 3 - 1;
+	if (size > PATH_MAX)
+		return -ENAMETOOLONG;
+
+	pr_debug("%s: depth = %d, size = %d\n", __FUNCTION__, depth, size);
+
+	for (s = path; depth--; s += 3)
+		strcpy(s,"../");
+
+	fill_object_path(target, path, size);
+	pr_debug("%s: path = '%s'\n", __FUNCTION__, path);
+
+	return 0;
+}
+
+static int sysfs_getlink(struct dentry *dentry, char * path)
+{
+	struct kobject *kobj, *target_kobj;
+	int error = 0;
+
+	kobj = sysfs_get_kobject(dentry->d_parent);
+	if (!kobj)
+		return -EINVAL;
+
+	target_kobj = sysfs_get_kobject(dentry);
+	if (!target_kobj) {
+		kobject_put(kobj);
+		return -EINVAL;
+	}
+
+	down_read(&sysfs_rename_sem);
+	error = sysfs_get_target_path(kobj, target_kobj, path);
+	up_read(&sysfs_rename_sem);
+	
+	kobject_put(kobj);
+	kobject_put(target_kobj);
+	return error;
+
+}
+
+int sysfs_readlink(struct dentry *dentry, char __user *buffer, int buflen)
+{
+	int error = 0;
+	unsigned long page = get_zeroed_page(GFP_KERNEL);
+
+	if (!page)
+		return -ENOMEM;
+
+	error = sysfs_getlink(dentry, (char *) page);
+	if (!error)
+	        error = vfs_readlink(dentry, buffer, buflen, (char *) page);
+
+	free_page(page);
+
+	return error;
+}
+
+int sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
+{
+	int error = 0;
+	unsigned long page = get_zeroed_page(GFP_KERNEL);
+
+	if (!page)
+		return -ENOMEM;
+
+	error = sysfs_getlink(dentry, (char *) page); 
+	if (!error)
+	        error = vfs_follow_link(nd, (char *) page);
+
+	free_page(page);
+
+	return error;
+}
 
 EXPORT_SYMBOL(sysfs_create_link);
 EXPORT_SYMBOL(sysfs_remove_link);
diff -Nru a/fs/sysfs/sysfs.h b/fs/sysfs/sysfs.h
--- a/fs/sysfs/sysfs.h	2004-05-25 21:22:09 -07:00
+++ b/fs/sysfs/sysfs.h	2004-05-25 21:22:09 -07:00
@@ -12,15 +12,18 @@
 extern int sysfs_create_subdir(struct kobject *, const char *, struct dentry **);
 extern void sysfs_remove_subdir(struct dentry *);
 
+extern int sysfs_readlink(struct dentry *, char __user *, int );
+extern int sysfs_follow_link(struct dentry *, struct nameidata *);
+extern struct rw_semaphore sysfs_rename_sem;
 
 static inline struct kobject *sysfs_get_kobject(struct dentry *dentry)
 {
 	struct kobject * kobj = NULL;
 
-	spin_lock(&dentry->d_lock);
+	spin_lock(&dcache_lock);
 	if (!d_unhashed(dentry))
 		kobj = kobject_get(dentry->d_fsdata);
-	spin_unlock(&dentry->d_lock);
+	spin_unlock(&dcache_lock);
 
 	return kobj;
 }
