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.
This commit is contained in:
Marcel Moolenaar 2014-07-30 16:08:16 +00:00
parent 4c20f7b8bb
commit f2fb1d4531
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=269308
2 changed files with 24 additions and 9 deletions

View File

@ -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);
}

View File

@ -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[];
/*