Skip to contentSkip to conversation

vfs: variant symlinks

PATCH NAK Ken Schmidt 3 participants 3 messages Sep 28, 2007 VFS

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 vfs: variant symlinks

Variant symlinks add the ability to embed variables in to the contents of symbolic links so their targets can change based on outside sources (user environment, uts, filesystems, etc.)

---

include/linux/variant.h +10 -0
diff -urN linux-2.6.22.5.orig/include/linux/variant.h linux-2.6.22.5/include/linux/variant.h
@@ -0,0 +1,10 @@
+#ifndef _LINUX_VARIANT_H
+#define _LINUX_VARIANT_H
+
+int variant_func_register(int ( *variant_func)(const char *, int, char *, int), int priority, char *name);
+void variant_func_unregister(int id);
+int do_variant_lookup(const char *path, char **newpath);
+
+extern int variant_links_enabled;
+
+#endif /* _LINUX_VARIANT_H */
fs/Kconfig +8 -0
diff -urN linux-2.6.22.5.orig/fs/Kconfig linux-2.6.22.5/fs/Kconfig
@@ -524,6 +524,14 @@
 
 	  If unsure, say Y.
 
+config VARIANT
+	bool "Variant symlink support (EXPERIMENTAL)"
+	depends on EXPERIMENTAL
+	help
+	  If you say Y here, all filesystems will have the ability to
+	  dynamically redirect their symbolic link targets based on embedded
+	  variables. If unsure, say N
+
 config QUOTA
 	bool "Quota support"
 	help
fs/Makefile +2 -0
diff -urN linux-2.6.22.5.orig/fs/Makefile linux-2.6.22.5/fs/Makefile
@@ -63,6 +63,8 @@
 
 obj-$(CONFIG_PROFILING)		+= dcookies.o
 obj-$(CONFIG_DLM)		+= dlm/
+
+obj-$(CONFIG_VARIANT)		+= variant/
  
 # Do not add any filesystems before this line
 obj-$(CONFIG_REISERFS_FS)	+= reiserfs/
fs/variant/Makefile +5 -0
diff -urN linux-2.6.22.5.orig/fs/variant/Makefile linux-2.6.22.5/fs/variant/Makefile
@@ -0,0 +1,5 @@
+#
+# Makefile for the variant symlinks
+#
+
+obj-$(CONFIG_VARIANT) += variant.o
fs/namei.c +21 -0
diff -urN linux-2.6.22.5.orig/fs/namei.c linux-2.6.22.5/fs/namei.c
@@ -31,6 +31,7 @@
 #include <linux/file.h>
 #include <linux/fcntl.h>
 #include <linux/namei.h>
+#include <linux/variant.h>
 #include <asm/namei.h>
 #include <asm/uaccess.h>
 
@@ -539,10 +540,25 @@
 static __always_inline int __vfs_follow_link(struct nameidata *nd, const char *link)
 {
 	int res = 0;
+#ifdef CONFIG_VARIANT
+	char *newlink = NULL;
+	int err;
+#endif
 	char *name;
 	if (IS_ERR(link))
 		goto fail;
 
+#ifdef CONFIG_VARIANT
+	if (variant_links_enabled && strchr(link, '$')) {
+		err = do_variant_lookup(link, &newlink);
+		if (err) {
+			path_release(nd);
+			return err;
+		}
+		link = newlink;
+	}
+#endif
+
 	if (*link == '/') {
 		path_release(nd);
 		if (!walk_init_root(link, nd))
@@ -551,6 +565,11 @@
 	}
 	res = link_path_walk(link, nd);
 out:
+#ifdef CONFIG_VARIANT
+	if (newlink == link)
+		kfree(newlink);
+#endif
+
 	if (nd->depth || res || nd->last_type!=LAST_NORM)
 		return res;
 	/*
fs/variant/variant.c +183 -0

183 lines not on this page · raw message

#1 lore raw
Quoted 3 lines · Ken Schmidt

Variant symlinks add the ability to embed variables in to the contents of symbolic links so their targets can change based on outside sources (user environment, uts, filesystems, etc.)

Could you elaborate why this is needed and what part cannot be solved in userspace (linkfarm on tmpfs or intelligent scripts)?

Thanks,

Jan

#2 lore raw
In reply to Ken Schmidt
Quoted 1 line · Ken Schmidt

Variant symlinks add the ability to embed variables in to the contents of symbolic links so their targets can change based on outside sources (user environment, uts, filesystems, etc.)

NAK - it's too ugly to live.