From owner-svn-src-head@FreeBSD.ORG Wed Jul 30 16:08:16 2014 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id C1BCD519; Wed, 30 Jul 2014 16:08:16 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id AF866229D; Wed, 30 Jul 2014 16:08:16 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id s6UG8GBq097898; Wed, 30 Jul 2014 16:08:16 GMT (envelope-from marcel@svn.freebsd.org) Received: (from marcel@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id s6UG8GcW097896; Wed, 30 Jul 2014 16:08:16 GMT (envelope-from marcel@svn.freebsd.org) Message-Id: <201407301608.s6UG8GcW097896@svn.freebsd.org> From: Marcel Moolenaar Date: Wed, 30 Jul 2014 16:08:16 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r269308 - head/lib/libstand X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 30 Jul 2014 16:08:16 -0000 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[]; /*