summaryrefslogtreecommitdiffstats
path: root/lib/libstand
diff options
context:
space:
mode:
authormarcel <marcel@FreeBSD.org>2014-07-30 16:08:16 +0000
committermarcel <marcel@FreeBSD.org>2014-07-30 16:08:16 +0000
commitd8a11be2f49dfce473c25414ca2679945573b969 (patch)
tree6dcae4d7486b406338a3dd38cf5f6f7538f6efb2 /lib/libstand
parent149d25e0606a9dc893480869e217ec049cf3d5ea (diff)
downloadFreeBSD-src-d8a11be2f49dfce473c25414ca2679945573b969.zip
FreeBSD-src-d8a11be2f49dfce473c25414ca2679945573b969.tar.gz
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.
Diffstat (limited to 'lib/libstand')
-rw-r--r--lib/libstand/open.c32
-rw-r--r--lib/libstand/stand.h1
2 files changed, 24 insertions, 9 deletions
diff --git a/lib/libstand/open.c b/lib/libstand/open.c
index 49dc660..0d90433 100644
--- a/lib/libstand/open.c
+++ b/lib/libstand/open.c
@@ -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);
}
diff --git a/lib/libstand/stand.h b/lib/libstand/stand.h
index 2808722..6c7e12d 100644
--- a/lib/libstand/stand.h
+++ b/lib/libstand/stand.h
@@ -364,6 +364,7 @@ extern int devopen(struct open_file *, const char *, const char **);
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[];
/*
OpenPOWER on IntegriCloud