[PATCH, E2FSPROGS] blkid: Automatically chose between ext4 and ext4dev as appropriate

2008-02-08 Thread Theodore Ts'o

I plan to release this in an upcoming 1.40.6 release, along with code
that allows tune2fs -E test_fs to work on ext4 filesystems.  The idea
is that if I can get this into community distro's, it will make it
easier for them to experiment with ext4/ext4dev, with the appropriate
forward compatibility when sometime (hopefully 2.6.26 or 2.6.27?) we
rename ext4dev to ext4.

Any comments before I push this change out to the maint branch?

- Ted


commit feac6e49211a44ef6f560b3b362fb132a474a471
Author: Theodore Ts'o [EMAIL PROTECTED]
Date:   Fri Feb 8 16:04:12 2008 -0500

blkid: Automatically chose between ext4 and ext4dev as appropriate

Add logic that on Linux systems will check for the presence of the
ext4dev filesystem; if it isn't present, fall back to ext4 for
filesystems that are marked as being OK for use on test filesystem
code.  If they are OK for use for in-development filesystem code, it
should also be fine to use stable filesystem code if there is no test
filesystem code (ext4dev) available.

The reverse is not true, of course.  We don't ever want to mount a
production filesystem using test filesystem code unless the user gives
us explicit permission via tune2fs -E test_fs.

Signed-off-by: Theodore Ts'o [EMAIL PROTECTED]

diff --git a/lib/blkid/probe.c b/lib/blkid/probe.c
index 492a36a..456e9bb 100644
--- a/lib/blkid/probe.c
+++ b/lib/blkid/probe.c
@@ -25,6 +25,7 @@
 #ifdef HAVE_SYS_MKDEV_H
 #include sys/mkdev.h
 #endif
+#include sys/utsname.h
 #ifdef HAVE_ERRNO_H
 #include errno.h
 #endif
@@ -158,6 +159,109 @@ static void get_ext2_info(blkid_dev dev, struct 
blkid_magic *id,
blkid_set_tag(dev, SEC_TYPE, ext2, sizeof(ext2));
 }
 
+/*
+ * Check to see if a filesystem is in /proc/filesystems.
+ * Returns 1 if found, 0 if not
+ */
+int fs_proc_check(const char *fs_name)
+{
+   FILE*f;
+   charbuf[80], *cp, *t;
+
+   f = fopen(/proc/filesystems, r);
+   if (!f)
+   return (0);
+   while (!feof(f)) {
+   if (!fgets(buf, sizeof(buf), f))
+   break;
+   cp = buf;
+   if (!isspace(*cp)) {
+   while (*cp  !isspace(*cp))
+   cp++;
+   }
+   while (*cp  isspace(*cp))
+   cp++;
+   if ((t = strchr(cp, '\n')) != NULL)
+   *t = 0;
+   if ((t = strchr(cp, '\t')) != NULL)
+   *t = 0;
+   if ((t = strchr(cp, ' ')) != NULL)
+   *t = 0;
+   if (!strcmp(fs_name, cp)) {
+   fclose(f);
+   return (1);
+   }
+   }
+   fclose(f);
+   return (0);
+}
+
+/*
+ * Check to see if a filesystem is available as a module
+ * Returns 1 if found, 0 if not
+ */
+int check_for_modules(const char *fs_name)
+{
+   struct utsname  uts;
+   FILE*f;
+   charbuf[1024], *cp, *t;
+   int i;
+
+   if (uname(uts))
+   return (0);
+   snprintf(buf, sizeof(buf), /lib/modules/%s/modules.dep, uts.release);
+
+   f = fopen(buf, r);
+   if (!f)
+   return (0);
+   while (!feof(f)) {
+   if (!fgets(buf, sizeof(buf), f))
+   break;
+   if ((cp = strchr(buf, ':')) != NULL)
+   *cp = 0;
+   else
+   continue;
+   if ((cp = strrchr(buf, '/')) != NULL)
+   cp++;
+   i = strlen(cp);
+   if (i  3) {
+   t = cp + i - 3;
+   if (!strcmp(t, .ko))
+   *t = 0;
+   }
+   if (!strcmp(cp, fs_name))
+   return (1);
+   }
+   fclose(f);
+   return (0);
+}
+
+static int system_supports_ext4()
+{
+   static time_t   last_check = 0;
+   static int  ret = -1;
+   time_t  now = time(0);
+
+   if (ret != -1 || (last_check - now)  5)
+   return ret;
+   last_check = now;
+   ret = (fs_proc_check(ext4) || check_for_modules(ext4));
+   return ret;
+}
+
+static int system_supports_ext4dev()
+{
+   static time_t   last_check = 0;
+   static int  ret = -1;
+   time_t  now = time(0);
+
+   if (ret != -1 || (last_check - now)  5)
+   return ret;
+   last_check = now;
+   ret = (fs_proc_check(ext4dev) || check_for_modules(ext4dev));
+   return ret;
+}
+
 static int probe_ext4dev(struct blkid_probe *probe,
 struct blkid_magic *id,
 unsigned char *buf)
@@ -165,10 +269,6 @@ static int probe_ext4dev(struct blkid_probe *probe,
struct ext2_super_block *es;
es = (struct ext2_super_block 

Re: [PATCH, E2FSPROGS] blkid: Automatically chose between ext4 and ext4dev as appropriate

2008-02-08 Thread Eric Sandeen
Theodore Ts'o wrote:
 I plan to release this in an upcoming 1.40.6 release, along with code
 that allows tune2fs -E test_fs to work on ext4 filesystems.  The idea
 is that if I can get this into community distro's, it will make it
 easier for them to experiment with ext4/ext4dev, with the appropriate
 forward compatibility when sometime (hopefully 2.6.26 or 2.6.27?) we
 rename ext4dev to ext4.
 
 Any comments before I push this change out to the maint branch?

Seems logically correct to me... although it also seems like this has
gotten fairly complex by now, what with blkid rummaging around in
modules.dep, /proc files, etc...

-Eric
-
To unsubscribe from this list: send the line unsubscribe linux-ext4 in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH, E2FSPROGS] blkid: Automatically chose between ext4 and ext4dev as appropriate

2008-02-08 Thread Theodore Tso
On Fri, Feb 08, 2008 at 04:50:37PM -0600, Eric Sandeen wrote:
 Theodore Ts'o wrote:
  I plan to release this in an upcoming 1.40.6 release, along with code
  that allows tune2fs -E test_fs to work on ext4 filesystems.  The idea
  is that if I can get this into community distro's, it will make it
  easier for them to experiment with ext4/ext4dev, with the appropriate
  forward compatibility when sometime (hopefully 2.6.26 or 2.6.27?) we
  rename ext4dev to ext4.
  
  Any comments before I push this change out to the maint branch?
 
 Seems logically correct to me... although it also seems like this has
 gotten fairly complex by now, what with blkid rummaging around in
 modules.dep, /proc files, etc...

True, but the good thing is that we only need to do this in one
location, and it does the right thing.  It also means that in the
future, even after ext4 is in production, if we want to do some
testing for some new optimizations or other ehancements in ext4, it's
a lot easier for us have both ext4 and ext4dev modules built at the
same time, where ext4dev would have our test code, and then once it's
stable and we're sure it's OK, we can commit it to mainline.  This
makes life much more convenient for an ext4 developer who wants to
both use it in production as well as having an alternate crash and
burn ext4dev code that he or she is trying out.

So one of the things that this does mean, is after we do the
ext4dev-ext4 transition, we have some way for users to give us
permission to disable the test_fs bit --- so that in the future, when
we have need of that bit, we can use it again and not have to worry
about old filesystems that are now in production but still have the
test_fs bit set.

- Ted
-
To unsubscribe from this list: send the line unsubscribe linux-ext4 in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html