svn commit: r269308 - head/lib/libstand

Marcel Moolenaar marcel at FreeBSD.org
Wed Jul 30 16:08:16 UTC 2014


Author: marcel
Date: Wed Jul 30 16:08:16 2014
New Revision: 269308
URL: http://svnweb.freebsd.org/changeset/base/269308

Log:
  Provide a means for loaders to control which file system to use. This
  to counteract the default behaviour of always trying each and every
  file system until one succeeds, or the open fails. The problem with the
  loader is that we've implemented features based on this behavior. The
  handling of compressed files is a good example of this. However, it is
  in general highly undesirable to not have a one-time probe (or taste
  in the geom lingo), followed by something similar to a mount whenever
  we (first) read from a device. Everytime we go to the same device, we
  can reasonably assume it (still) has the same file system. For file
  systems that need to do far more that a trivial read of a super block,
  not having something similar to a mount operation is disastrous from
  a performance (and thus usability) perspective.
  
  But, again, since we've implemented features based on this stateless
  approach, things can get complicated quickly if and when we want to
  change this. And yet, we sometimes do need stateful behaviour.
  
  For this reason, this change simply introduces exclusive_file_system.
  When set to the fsops of the file system to use, the open call will
  only try this file system. Setting it to NULL restores the default
  behaviour. It's a low-cost (low-brow?) approach to provide enough
  control without re-implementing the guts of the loader.
  
  A good example of when this is useful is when we're trying to load
  files out of a container (say, a software packaga) that itself lives
  on a file system or is fetched over the network. While opening the
  container can be done in the normal stateless manner, once it is
  opened, subsequent opens should only consider the container.
  
  Obtained from:	Juniper Networks, Inc.

Modified:
  head/lib/libstand/open.c
  head/lib/libstand/stand.h

Modified: head/lib/libstand/open.c
==============================================================================
--- head/lib/libstand/open.c	Wed Jul 30 15:43:17 2014	(r269307)
+++ head/lib/libstand/open.c	Wed Jul 30 16:08:16 2014	(r269308)
@@ -65,6 +65,8 @@ __FBSDID("$FreeBSD$");
 
 #include "stand.h"
 
+struct fs_ops *exclusive_file_system;
+
 struct open_file files[SOPEN_MAX];
 
 static int
@@ -89,6 +91,7 @@ o_rainit(struct open_file *f)
 int
 open(const char *fname, int mode)
 {
+    struct fs_ops	*fs;
     struct open_file	*f;
     int			fd, i, error, besterror;
     const char		*file;
@@ -105,6 +108,15 @@ open(const char *fname, int mode)
     f->f_offset = 0;
     f->f_devdata = NULL;
     file = (char *)0;
+
+    if (exclusive_file_system != NULL) {
+	fs = exclusive_file_system;
+	error = (fs->fo_open)(fname, f);
+	if (error == 0)
+	    goto ok;
+	goto fail;
+    }
+
     error = devopen(f, fname, &file);
     if (error ||
 	(((f->f_flags & F_NODEV) == 0) && f->f_dev == (struct devsw *)0))
@@ -120,20 +132,17 @@ open(const char *fname, int mode)
     /* pass file name to the different filesystem open routines */
     besterror = ENOENT;
     for (i = 0; file_system[i] != NULL; i++) {
-
-	error = ((*file_system[i]).fo_open)(file, f);
-	if (error == 0) {
-	    
-	    f->f_ops = file_system[i];
-	    o_rainit(f);
-	    return (fd);
-	}
+	fs = file_system[i];
+	error = (fs->fo_open)(file, f);
+	if (error == 0)
+	    goto ok;
 	if (error != EINVAL)
 	    besterror = error;
     }
     error = besterror;
 
-    if ((f->f_flags & F_NODEV) == 0)
+ fail:
+    if ((f->f_flags & F_NODEV) == 0 && f->f_dev != NULL)
 	f->f_dev->dv_close(f);
     if (error)
 	devclose(f);
@@ -142,4 +151,9 @@ open(const char *fname, int mode)
     f->f_flags = 0;
     errno = error;
     return (-1);
+
+ ok:
+    f->f_ops = fs;
+    o_rainit(f);
+    return (fd);
 }

Modified: head/lib/libstand/stand.h
==============================================================================
--- head/lib/libstand/stand.h	Wed Jul 30 15:43:17 2014	(r269307)
+++ head/lib/libstand/stand.h	Wed Jul 30 16:08:16 2014	(r269308)
@@ -364,6 +364,7 @@ extern int		devopen(struct open_file *, 
 extern int		devclose(struct open_file *f);
 extern void		panic(const char *, ...) __dead2 __printflike(1, 2);
 extern struct fs_ops	*file_system[];
+extern struct fs_ops	*exclusive_file_system;
 extern struct devsw	*devsw[];
 
 /*


More information about the svn-src-all mailing list