2011-02-17 12:59:01

by Masatake YAMATO

[permalink] [raw]
Subject: [PATCH 1/2] Read /etc/exports.d/*.export as extra export files

This patch adding a capability to read /etc/exports.d/*.export as
extra export files to exportfs.

If one wants to add or remove an export entry in a script, currently
one may have to use sed or something tool for adding or removing the
line for the entry in /etc/exports file.

With the patch, adding and removing an entry from a script is much easier.
cat<<EOF... or mv can be used for adding. rm can be used for removing.


Signed-off-by: Masatake YAMATO <[email protected]>
---
support/include/nfslib.h | 6 ++++
utils/exportfs/exportfs.c | 59 ++++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 64 insertions(+), 1 deletions(-)

diff --git a/support/include/nfslib.h b/support/include/nfslib.h
index 53ece0e..864aae2 100644
--- a/support/include/nfslib.h
+++ b/support/include/nfslib.h
@@ -25,6 +25,12 @@
#ifndef _PATH_EXPORTS
#define _PATH_EXPORTS "/etc/exports"
#endif
+#ifndef _PATH_EXPORTS_D
+#define _PATH_EXPORTS_D "/etc/exports.d"
+#endif
+#ifndef _EXT_EXPORT
+#define _EXT_EXPORT ".export"
+#endif
#ifndef _PATH_IDMAPDCONF
#define _PATH_IDMAPDCONF "/etc/idmapd.conf"
#endif
diff --git a/utils/exportfs/exportfs.c b/utils/exportfs/exportfs.c
index b78957f..26d0504 100644
--- a/utils/exportfs/exportfs.c
+++ b/utils/exportfs/exportfs.c
@@ -25,6 +25,7 @@
#include <fcntl.h>
#include <netdb.h>
#include <errno.h>
+#include <dirent.h>

#include "sockaddr.h"
#include "misc.h"
@@ -41,6 +42,7 @@ static void error(nfs_export *exp, int err);
static void usage(const char *progname);
static void validate_export(nfs_export *exp);
static int matchhostname(const char *hostname1, const char *hostname2);
+static void export_d_read(const char *dname);

int
main(int argc, char **argv)
@@ -127,8 +129,10 @@ main(int argc, char **argv)
return 0;
}
}
- if (f_export && ! f_ignore)
+ if (f_export && ! f_ignore) {
export_read(_PATH_EXPORTS);
+ export_d_read(_PATH_EXPORTS_D);
+ }
if (f_export) {
if (f_all)
export_all(f_verbose);
@@ -485,6 +489,59 @@ out:
return result;
}

+/* Based on mnt_table_parse_dir() in
+ util-linux-ng/shlibs/mount/src/tab_parse.c */
+static void
+export_d_read(const char *dname)
+{
+ int n = 0, i;
+ struct dirent **namelist = NULL;
+
+
+ n = scandir(dname, &namelist, NULL, versionsort);
+ if (n < 0)
+ xlog(L_NOTICE, "scandir %s: %s\n", dname, strerror(errno));
+ else if (n == 0)
+ return;
+
+ for (i = 0; i < n; i++) {
+ struct dirent *d = namelist[i];
+ size_t namesz;
+ char fname[PATH_MAX + 1];
+ int fname_len;
+
+
+ if (d->d_type != DT_UNKNOWN
+ && d->d_type != DT_REG
+ && d->d_type != DT_LNK)
+ continue;
+ if (*d->d_name == '.')
+ continue;
+
+#define _EXT_EXPORT_SIZ (sizeof(_EXT_EXPORT) - 1)
+ namesz = strlen(d->d_name);
+ if (!namesz
+ || namesz < _EXT_EXPORT_SIZ + 1
+ || strcmp(d->d_name + (namesz - _EXT_EXPORT_SIZ),
+ _EXT_EXPORT))
+ continue;
+
+ fname_len = snprintf(fname, PATH_MAX +1, "%s/%s", dname, d->d_name);
+ if (fname_len > PATH_MAX) {
+ xlog(L_WARNING, "Too long file name: %s in %s\n", d->d_name, dname);
+ continue;
+ }
+
+ export_read(fname);
+ }
+
+ for (i = 0; i < n; i++)
+ free(namelist[i]);
+ free(namelist);
+
+ return;
+}
+
static char
dumpopt(char c, char *fmt, ...)
{
--
1.7.4



2011-02-17 13:03:12

by Masatake YAMATO

[permalink] [raw]
Subject: [PATCH 2/2] Update man pages for /etc/exports.d

Man page updates for /etc/exports.d.

Signed-off-by: Masatake YAMATO <[email protected]>
---
utils/exportfs/exportfs.man | 32 +++++++++++++++++++++++++++-----
utils/exportfs/exports.man | 19 +++++++++++++++++++
2 files changed, 46 insertions(+), 5 deletions(-)

diff --git a/utils/exportfs/exportfs.man b/utils/exportfs/exportfs.man
index 089f75b..7de0aef 100644
--- a/utils/exportfs/exportfs.man
+++ b/utils/exportfs/exportfs.man
@@ -37,11 +37,15 @@ when a client sends an NFS MOUNT request.
.PP
Normally the master export table is initialized with the contents of
.I /etc/exports
+and files under
+.I /etc/exports.d
by invoking
.BR "exportfs -a" .
However, a system administrator can choose to add or delete
exports without modifying
.I /etc/exports
+or files under
+.I /etc/exports.d
by using the
.B exportfs
command.
@@ -92,17 +96,24 @@ Specify a list of export options in the same manner as in
.B -i
Ignore the
.I /etc/exports
-file. Only default options and options given on the command line are used.
+file and files under
+.I /etc/exports.d
+directory. Only default options and options given on the command line are used.
.TP
.B -r
Reexport all directories, synchronizing
.I /var/lib/nfs/etab
with
-.IR /etc/exports .
+.IR /etc/exports
+and files under
+.IR /etc/exports.d .
This option removes entries in
.I /var/lib/nfs/etab
which have been deleted from
-.I /etc/exports, and removes any entries from the
+.I /etc/exports
+or files under
+.IR /etc/exports.d ,
+and removes any entries from the
kernel export table which are no longer valid.
.TP
.B -u
@@ -130,6 +141,8 @@ when adding new entries to the export table. When using
.BR "exportfs -a" ,
all exports listed in
.I /etc/exports
+and files under
+.I /etc/exports.d
are added to
.IR /var/lib/nfs/etab .
The kernel's export table is also updated as needed.
@@ -149,7 +162,9 @@ several sources.
The default export options are
.BR sync,ro,root_squash,wdelay .
These can be overridden by entries in
-.IR /etc/exports .
+.IR /etc/exports
+or files under
+.IR /etc/exports.d .
.PP
A system administrator may override options from these sources using the
.B -o
@@ -188,6 +203,8 @@ to display the export options for each export.
.SH EXAMPLES
The following adds all directories listed in
.I /etc/exports
+and files under
+.I /etc/exports.d
to
.I /var/lib/nfs/etab
and pushes the resulting export entries into the kernel:
@@ -215,7 +232,9 @@ directory:
.fi
.PP
To unexport all exports listed in
-.IR /etc/exports :
+.IR /etc/exports
+and files under
+.IR /etc/exports.d :
.PP
.nf
.B "# exportfs -au
@@ -238,6 +257,9 @@ if they themselves are no longer valid they will be removed.
.I /etc/exports
input file listing exports, export options, and access control lists
.TP 2.5i
+.I /etc/exports.d
+directory where extra input files are stored
+.TP 2.5i
.I /var/lib/nfs/etab
master table of exports
.TP 2.5i
diff --git a/utils/exportfs/exports.man b/utils/exportfs/exports.man
index 4e3edc5..db49165 100644
--- a/utils/exportfs/exports.man
+++ b/utils/exportfs/exports.man
@@ -444,6 +444,24 @@ export entry for
.B /home/joe
in the example section below, which maps all requests to uid 150 (which
is supposedly that of user joe).
+.SS Extra Export Tables
+After reading
+.I /etc/exports
+.B exportfs
+reads files under
+.I /etc/exports.d.
+directory as extra export tables.
+.B exportfs
+regards only a file which name is ended with
+.I .export
+and
+not started with
+.I .
+as an extra export file. A file which name
+is not met this condition is just ignored.
+The format for extra export tables is the same as
+.I /etc/exports
+.
.IP
.SH EXAMPLE
.PP
@@ -489,6 +507,7 @@ all three mounts with the `sync' option enabled.
'''entry.
.SH FILES
/etc/exports
+/etc/exports.d
.SH SEE ALSO
.BR exportfs (8),
.BR netgroup (5),
--
1.7.4


2011-03-03 15:26:43

by Ferenc Wagner

[permalink] [raw]
Subject: Re: [PATCH 1/2] Read /etc/exports.d/*.export as extra export files

Masatake YAMATO <[email protected]> writes:

> No comment?

I like the idea and find the approach sane, but I'm just a user.
--
Regards,
Feri.

2011-03-07 14:17:24

by Steve Dickson

[permalink] [raw]
Subject: Re: [PATCH 1/2] Read /etc/exports.d/*.export as extra export files



On 03/07/2011 09:02 AM, Jim Rees wrote:
> Steve Dickson wrote:
>
> True... But I noticed the suffix that gvim looks for is ".exports"
> not ".export".
>
> Is the exports file format so complicated that we need syntax highlighting?
Probably not... ;-) I just noticed there was a syntax highlighter called
".exports" in gvim...

steved.

2011-03-07 13:17:29

by Steve Dickson

[permalink] [raw]
Subject: Re: [PATCH 1/2] Read /etc/exports.d/*.export as extra export files



On 03/07/2011 08:05 AM, Steve Dickson wrote:
>
>
> On 03/06/2011 01:11 AM, Masatake YAMATO wrote:
>> On Sat, 5 Mar 2011 20:51:06 -0500, Jim Rees <[email protected]> wrote
>>> Steve Dickson wrote:
>>>
>>> Now, I realize you added the ".export" explanation to the man page
>>> but is there a particular reason why file in that directory have
>>> to end with ".export"? Out of "easy of use" sake, should any
>>> and all files that exist in that directory be expected to
>>> be exports files?
>>>
>>> I don't know if that's the best way to do it, but I think it would be useful
>>> to have a way to keep files in the directory that don't get automatically
>>> read. As an analogy, I have the following files in my /etc/init:
>>>
>>> portmap.conf This is the real one that gets used
>>> portmap.conf~ This is a backup file produced by emacs
>>> portmap.conf-20100603 This is the file that came with my distro
>>>
>>> Only the first one gets used, which is what I want, because it's the only
>>> one ending in ".conf".
> This makes sense...
>
>>
>> Jim, thank you for explanation. He wrote what I'd like to write.
>>
>> This technique is borrowed from util-linux-ng; libmount.so reads
>> only *.fstab under /etc/fstab.d.
>>
>>
>> In addition, ".export" suffix tells an editor which syntax highlighter
>> should be used when editing .export file:P
> True... But I noticed the suffix that gvim looks for is ".exports"
> not ".export".
>
> What editor are you using and does it look for a ".export" by default?
>
After thinking about this a little longer, I think making the
suffix ".exports" does make sense. Along with the that being
the default syntax highlighter for gvim, more importantly, its
also the name of the man page, exports(5).

steved.

2011-03-05 22:46:12

by Steve Dickson

[permalink] [raw]
Subject: Re: [PATCH 1/2] Read /etc/exports.d/*.export as extra export files

Hello,

On 02/17/2011 07:59 AM, Masatake YAMATO wrote:
> This patch adding a capability to read /etc/exports.d/*.export as
> extra export files to exportfs.
>
> If one wants to add or remove an export entry in a script, currently
> one may have to use sed or something tool for adding or removing the
> line for the entry in /etc/exports file.
>
> With the patch, adding and removing an entry from a script is much easier.
> cat<<EOF... or mv can be used for adding. rm can be used for removing.
>
>
> Signed-off-by: Masatake YAMATO <[email protected]>
> ---
> support/include/nfslib.h | 6 ++++
> utils/exportfs/exportfs.c | 59 ++++++++++++++++++++++++++++++++++++++++++++-
> 2 files changed, 64 insertions(+), 1 deletions(-)
>
> diff --git a/support/include/nfslib.h b/support/include/nfslib.h
> index 53ece0e..864aae2 100644
> --- a/support/include/nfslib.h
> +++ b/support/include/nfslib.h
> @@ -25,6 +25,12 @@
> #ifndef _PATH_EXPORTS
> #define _PATH_EXPORTS "/etc/exports"
> #endif
> +#ifndef _PATH_EXPORTS_D
> +#define _PATH_EXPORTS_D "/etc/exports.d"
> +#endif
> +#ifndef _EXT_EXPORT
> +#define _EXT_EXPORT ".export"
Question: Why do we care about the format of the file that lives in
the _PATH_EXPORTS_D directory? The reason I asked is I created a file
called 'root.exports' which silently failed export those exports.

Now, I realize you added the ".export" explanation to the man page
but is there a particular reason why file in that directory have
to end with ".export"? Out of "easy of use" sake, should any
and all files that exist in that directory be expected to
be exports files?

steved.


> +#endif
> #ifndef _PATH_IDMAPDCONF
> #define _PATH_IDMAPDCONF "/etc/idmapd.conf"
> #endif
> diff --git a/utils/exportfs/exportfs.c b/utils/exportfs/exportfs.c
> index b78957f..26d0504 100644
> --- a/utils/exportfs/exportfs.c
> +++ b/utils/exportfs/exportfs.c
> @@ -25,6 +25,7 @@
> #include <fcntl.h>
> #include <netdb.h>
> #include <errno.h>
> +#include <dirent.h>
>
> #include "sockaddr.h"
> #include "misc.h"
> @@ -41,6 +42,7 @@ static void error(nfs_export *exp, int err);
> static void usage(const char *progname);
> static void validate_export(nfs_export *exp);
> static int matchhostname(const char *hostname1, const char *hostname2);
> +static void export_d_read(const char *dname);
>
> int
> main(int argc, char **argv)
> @@ -127,8 +129,10 @@ main(int argc, char **argv)
> return 0;
> }
> }
> - if (f_export && ! f_ignore)
> + if (f_export && ! f_ignore) {
> export_read(_PATH_EXPORTS);
> + export_d_read(_PATH_EXPORTS_D);
> + }
> if (f_export) {
> if (f_all)
> export_all(f_verbose);
> @@ -485,6 +489,59 @@ out:
> return result;
> }
>
> +/* Based on mnt_table_parse_dir() in
> + util-linux-ng/shlibs/mount/src/tab_parse.c */
> +static void
> +export_d_read(const char *dname)
> +{
> + int n = 0, i;
> + struct dirent **namelist = NULL;
> +
> +
> + n = scandir(dname, &namelist, NULL, versionsort);
> + if (n < 0)
> + xlog(L_NOTICE, "scandir %s: %s\n", dname, strerror(errno));
> + else if (n == 0)
> + return;
> +
> + for (i = 0; i < n; i++) {
> + struct dirent *d = namelist[i];
> + size_t namesz;
> + char fname[PATH_MAX + 1];
> + int fname_len;
> +
> +
> + if (d->d_type != DT_UNKNOWN
> + && d->d_type != DT_REG
> + && d->d_type != DT_LNK)
> + continue;
> + if (*d->d_name == '.')
> + continue;
> +
> +#define _EXT_EXPORT_SIZ (sizeof(_EXT_EXPORT) - 1)
> + namesz = strlen(d->d_name);
> + if (!namesz
> + || namesz < _EXT_EXPORT_SIZ + 1
> + || strcmp(d->d_name + (namesz - _EXT_EXPORT_SIZ),
> + _EXT_EXPORT))
> + continue;
> +
> + fname_len = snprintf(fname, PATH_MAX +1, "%s/%s", dname, d->d_name);
> + if (fname_len > PATH_MAX) {
> + xlog(L_WARNING, "Too long file name: %s in %s\n", d->d_name, dname);
> + continue;
> + }
> +
> + export_read(fname);
> + }
> +
> + for (i = 0; i < n; i++)
> + free(namelist[i]);
> + free(namelist);
> +
> + return;
> +}
> +
> static char
> dumpopt(char c, char *fmt, ...)
> {

2011-03-07 14:29:17

by Steve Dickson

[permalink] [raw]
Subject: Re: [PATCH 1/2] Read /etc/exports.d/*.export as extra export files

Hello,

On 02/17/2011 07:59 AM, Masatake YAMATO wrote:
> This patch adding a capability to read /etc/exports.d/*.export as
> extra export files to exportfs.
>
> If one wants to add or remove an export entry in a script, currently
> one may have to use sed or something tool for adding or removing the
> line for the entry in /etc/exports file.
>
> With the patch, adding and removing an entry from a script is much easier.
> cat<<EOF... or mv can be used for adding. rm can be used for removing.
>
>
> Signed-off-by: Masatake YAMATO <[email protected]>
Committed with the 's/.export/.exports/g' change...

Again, thanks for your patience!

steved.

> ---
> support/include/nfslib.h | 6 ++++
> utils/exportfs/exportfs.c | 59 ++++++++++++++++++++++++++++++++++++++++++++-
> 2 files changed, 64 insertions(+), 1 deletions(-)
>
> diff --git a/support/include/nfslib.h b/support/include/nfslib.h
> index 53ece0e..864aae2 100644
> --- a/support/include/nfslib.h
> +++ b/support/include/nfslib.h
> @@ -25,6 +25,12 @@
> #ifndef _PATH_EXPORTS
> #define _PATH_EXPORTS "/etc/exports"
> #endif
> +#ifndef _PATH_EXPORTS_D
> +#define _PATH_EXPORTS_D "/etc/exports.d"
> +#endif
> +#ifndef _EXT_EXPORT
> +#define _EXT_EXPORT ".export"
> +#endif
> #ifndef _PATH_IDMAPDCONF
> #define _PATH_IDMAPDCONF "/etc/idmapd.conf"
> #endif
> diff --git a/utils/exportfs/exportfs.c b/utils/exportfs/exportfs.c
> index b78957f..26d0504 100644
> --- a/utils/exportfs/exportfs.c
> +++ b/utils/exportfs/exportfs.c
> @@ -25,6 +25,7 @@
> #include <fcntl.h>
> #include <netdb.h>
> #include <errno.h>
> +#include <dirent.h>
>
> #include "sockaddr.h"
> #include "misc.h"
> @@ -41,6 +42,7 @@ static void error(nfs_export *exp, int err);
> static void usage(const char *progname);
> static void validate_export(nfs_export *exp);
> static int matchhostname(const char *hostname1, const char *hostname2);
> +static void export_d_read(const char *dname);
>
> int
> main(int argc, char **argv)
> @@ -127,8 +129,10 @@ main(int argc, char **argv)
> return 0;
> }
> }
> - if (f_export && ! f_ignore)
> + if (f_export && ! f_ignore) {
> export_read(_PATH_EXPORTS);
> + export_d_read(_PATH_EXPORTS_D);
> + }
> if (f_export) {
> if (f_all)
> export_all(f_verbose);
> @@ -485,6 +489,59 @@ out:
> return result;
> }
>
> +/* Based on mnt_table_parse_dir() in
> + util-linux-ng/shlibs/mount/src/tab_parse.c */
> +static void
> +export_d_read(const char *dname)
> +{
> + int n = 0, i;
> + struct dirent **namelist = NULL;
> +
> +
> + n = scandir(dname, &namelist, NULL, versionsort);
> + if (n < 0)
> + xlog(L_NOTICE, "scandir %s: %s\n", dname, strerror(errno));
> + else if (n == 0)
> + return;
> +
> + for (i = 0; i < n; i++) {
> + struct dirent *d = namelist[i];
> + size_t namesz;
> + char fname[PATH_MAX + 1];
> + int fname_len;
> +
> +
> + if (d->d_type != DT_UNKNOWN
> + && d->d_type != DT_REG
> + && d->d_type != DT_LNK)
> + continue;
> + if (*d->d_name == '.')
> + continue;
> +
> +#define _EXT_EXPORT_SIZ (sizeof(_EXT_EXPORT) - 1)
> + namesz = strlen(d->d_name);
> + if (!namesz
> + || namesz < _EXT_EXPORT_SIZ + 1
> + || strcmp(d->d_name + (namesz - _EXT_EXPORT_SIZ),
> + _EXT_EXPORT))
> + continue;
> +
> + fname_len = snprintf(fname, PATH_MAX +1, "%s/%s", dname, d->d_name);
> + if (fname_len > PATH_MAX) {
> + xlog(L_WARNING, "Too long file name: %s in %s\n", d->d_name, dname);
> + continue;
> + }
> +
> + export_read(fname);
> + }
> +
> + for (i = 0; i < n; i++)
> + free(namelist[i]);
> + free(namelist);
> +
> + return;
> +}
> +
> static char
> dumpopt(char c, char *fmt, ...)
> {

2011-03-03 20:52:17

by Steve Dickson

[permalink] [raw]
Subject: Re: [PATCH 1/2] Read /etc/exports.d/*.export as extra export files



On 03/03/2011 09:01 AM, Masatake YAMATO wrote:
> No comment?
Sorry about that... I was traveling for the couple weeks...

Would you happen to have an example script on how
this new feature would be used? I just want to run
some quick tests...

tia,

steved.

>
>
> Masatake YAMATO
>
>> This patch adding a capability to read /etc/exports.d/*.export as
>> extra export files to exportfs.
>>
>> If one wants to add or remove an export entry in a script, currently
>> one may have to use sed or something tool for adding or removing the
>> line for the entry in /etc/exports file.
>>
>> With the patch, adding and removing an entry from a script is much easier.
>> cat<<EOF... or mv can be used for adding. rm can be used for removing.
>>
>>
>> Signed-off-by: Masatake YAMATO <[email protected]>
>> ---
>> support/include/nfslib.h | 6 ++++
>> utils/exportfs/exportfs.c | 59 ++++++++++++++++++++++++++++++++++++++++++++-
>> 2 files changed, 64 insertions(+), 1 deletions(-)
>>
>> diff --git a/support/include/nfslib.h b/support/include/nfslib.h
>> index 53ece0e..864aae2 100644
>> --- a/support/include/nfslib.h
>> +++ b/support/include/nfslib.h
>> @@ -25,6 +25,12 @@
>> #ifndef _PATH_EXPORTS
>> #define _PATH_EXPORTS "/etc/exports"
>> #endif
>> +#ifndef _PATH_EXPORTS_D
>> +#define _PATH_EXPORTS_D "/etc/exports.d"
>> +#endif
>> +#ifndef _EXT_EXPORT
>> +#define _EXT_EXPORT ".export"
>> +#endif
>> #ifndef _PATH_IDMAPDCONF
>> #define _PATH_IDMAPDCONF "/etc/idmapd.conf"
>> #endif
>> diff --git a/utils/exportfs/exportfs.c b/utils/exportfs/exportfs.c
>> index b78957f..26d0504 100644
>> --- a/utils/exportfs/exportfs.c
>> +++ b/utils/exportfs/exportfs.c
>> @@ -25,6 +25,7 @@
>> #include <fcntl.h>
>> #include <netdb.h>
>> #include <errno.h>
>> +#include <dirent.h>
>>
>> #include "sockaddr.h"
>> #include "misc.h"
>> @@ -41,6 +42,7 @@ static void error(nfs_export *exp, int err);
>> static void usage(const char *progname);
>> static void validate_export(nfs_export *exp);
>> static int matchhostname(const char *hostname1, const char *hostname2);
>> +static void export_d_read(const char *dname);
>>
>> int
>> main(int argc, char **argv)
>> @@ -127,8 +129,10 @@ main(int argc, char **argv)
>> return 0;
>> }
>> }
>> - if (f_export && ! f_ignore)
>> + if (f_export && ! f_ignore) {
>> export_read(_PATH_EXPORTS);
>> + export_d_read(_PATH_EXPORTS_D);
>> + }
>> if (f_export) {
>> if (f_all)
>> export_all(f_verbose);
>> @@ -485,6 +489,59 @@ out:
>> return result;
>> }
>>
>> +/* Based on mnt_table_parse_dir() in
>> + util-linux-ng/shlibs/mount/src/tab_parse.c */
>> +static void
>> +export_d_read(const char *dname)
>> +{
>> + int n = 0, i;
>> + struct dirent **namelist = NULL;
>> +
>> +
>> + n = scandir(dname, &namelist, NULL, versionsort);
>> + if (n < 0)
>> + xlog(L_NOTICE, "scandir %s: %s\n", dname, strerror(errno));
>> + else if (n == 0)
>> + return;
>> +
>> + for (i = 0; i < n; i++) {
>> + struct dirent *d = namelist[i];
>> + size_t namesz;
>> + char fname[PATH_MAX + 1];
>> + int fname_len;
>> +
>> +
>> + if (d->d_type != DT_UNKNOWN
>> + && d->d_type != DT_REG
>> + && d->d_type != DT_LNK)
>> + continue;
>> + if (*d->d_name == '.')
>> + continue;
>> +
>> +#define _EXT_EXPORT_SIZ (sizeof(_EXT_EXPORT) - 1)
>> + namesz = strlen(d->d_name);
>> + if (!namesz
>> + || namesz < _EXT_EXPORT_SIZ + 1
>> + || strcmp(d->d_name + (namesz - _EXT_EXPORT_SIZ),
>> + _EXT_EXPORT))
>> + continue;
>> +
>> + fname_len = snprintf(fname, PATH_MAX +1, "%s/%s", dname, d->d_name);
>> + if (fname_len > PATH_MAX) {
>> + xlog(L_WARNING, "Too long file name: %s in %s\n", d->d_name, dname);
>> + continue;
>> + }
>> +
>> + export_read(fname);
>> + }
>> +
>> + for (i = 0; i < n; i++)
>> + free(namelist[i]);
>> + free(namelist);
>> +
>> + return;
>> +}
>> +
>> static char
>> dumpopt(char c, char *fmt, ...)
>> {
>> --
>> 1.7.4
>>
>> --
>> To unsubscribe from this list: send the line "unsubscribe linux-nfs" in
>> the body of a message to [email protected]
>> More majordomo info at http://vger.kernel.org/majordomo-info.html
> --
> To unsubscribe from this list: send the line "unsubscribe linux-nfs" in
> the body of a message to [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html

2011-03-07 13:05:42

by Steve Dickson

[permalink] [raw]
Subject: Re: [PATCH 1/2] Read /etc/exports.d/*.export as extra export files



On 03/06/2011 01:11 AM, Masatake YAMATO wrote:
> On Sat, 5 Mar 2011 20:51:06 -0500, Jim Rees <[email protected]> wrote
>> Steve Dickson wrote:
>>
>> Now, I realize you added the ".export" explanation to the man page
>> but is there a particular reason why file in that directory have
>> to end with ".export"? Out of "easy of use" sake, should any
>> and all files that exist in that directory be expected to
>> be exports files?
>>
>> I don't know if that's the best way to do it, but I think it would be useful
>> to have a way to keep files in the directory that don't get automatically
>> read. As an analogy, I have the following files in my /etc/init:
>>
>> portmap.conf This is the real one that gets used
>> portmap.conf~ This is a backup file produced by emacs
>> portmap.conf-20100603 This is the file that came with my distro
>>
>> Only the first one gets used, which is what I want, because it's the only
>> one ending in ".conf".
This makes sense...

>
> Jim, thank you for explanation. He wrote what I'd like to write.
>
> This technique is borrowed from util-linux-ng; libmount.so reads
> only *.fstab under /etc/fstab.d.
>
>
> In addition, ".export" suffix tells an editor which syntax highlighter
> should be used when editing .export file:P
True... But I noticed the suffix that gvim looks for is ".exports"
not ".export".

What editor are you using and does it look for a ".export" by default?

steved.

2011-03-05 16:54:33

by Masatake YAMATO

[permalink] [raw]
Subject: Re: [PATCH 1/2] Read /etc/exports.d/*.export as extra export files

On Fri, 04 Mar 2011 11:21:54 -0500, Steve Dickson <[email protected]> wrote
>
>
> On 03/04/2011 01:10 AM, Masatake YAMATO wrote:
>> Hi,
>>
>> thank you for replying.
> Again.. my apologies for taking so long...
>
>>
>>> On 03/03/2011 09:01 AM, Masatake YAMATO wrote:
>>>> No comment?
>>> Sorry about that... I was traveling for the couple weeks...
>>>
>>> Would you happen to have an example script on how
>>> this new feature would be used? I just want to run
>>> some quick tests...
>>>
>>> tia,
>>>
>>> steved.
>>
>> Could you try following one?
>>
>> # cd /tmp
>> # mkdir /tmp/alpha
>> # mkdir /tmp/beta
>> # mkdir /etc/exports.d
>> # mkdir /etc/exports.d
>> # echo '/tmp/alpha *(ro)' > /etc/exports.d/alpha.export
>> # echo '/tmp/beta *(ro)' > /etc/exports.d/beta.export
>> # /etc/init.d nfs restart
>>
>> After above setting up, when you do `exportfs', following lines
>> may be included in the output:
>>
>> /tmp/alpha <world>
>> /tmp/beta <world>
> Question... Where is the race? Meaning who is reading the exports
> file while its being modified?

Sorry, I don't understand well. Are you talking about race condition
introduced with my patch?

> The reason I ask is exporting (or re-exporting) pretty serial:
>
> exportfs read /etc/exports
> exportfs writes the new exports to /var/lib/nfs/etab
> mountd notices etab has changed and rereads its.
> mountd flush the kernel cache cause the kernel to do upcalls to get the new exports.

With my patch doesn't change match this sequence:

(S1) exportfs read /etc/exports
(S2) exportfs read /etc/exports.d/*.export
(S3) exportfs writes the new exports to /var/lib/nfs/etab
(S4) mountd notices etab has changed and rereads its.
(S5) mountd flush the kernel cache cause the kernel to do upcalls to get the new exports.

I've added (Sn) to make discussion easier. I've just added S2 stage.

> So since exportfs command not a daemon I don't see why
> cp exports.new /etc/exports && exportfs -arv
>
> isn't all that is needed. What am I missing?

Consider the case when an user wants to add following entry to /etc/exports:

'/tmp/alpha *(ro)'

How one will do? Without my patch I image following sequence (sequence 1).

cp /etc/exports exports.new
echo '/tmp/alpha *(ro)' >> exports.new
cp exports.new /etc/exports && exportfs -arv

With my patch this sequence becomes simplified as (sequence 1'):

echo '/tmp/alpha *(ro)' > /etc/exports.d/alpha.export
exportfs -arv

When duplicated entries must be considered the sequence 1 may become
more complex.


Next, consider removing the export entry from /etc/exports.
Without my patch I image following sequence (sequence 2).

cp /etc/exports exports.old
grep -v '/tmp/alpha *(ro)' < exports.old > /etc/exports
exportfs -arv

With my patch this sequence becomes simplified as (sequence 2'):
rm /etc/exports.d/alpha.export
exportfs -arv



More background I'm thinking expanding the area of utilizing rpm package
in system management. Consider installing an export entry to a system
via rpm package. Without my patch you have to write down sequence 1
to %post and sequence 2 to %postun of the spec file. With my patch
you have to just put /etc/exports.d/alpha.export to %files section.

This story of rpm is just my application. However, I thik my patch may be
useful for other purposes.


Masatake YAMATO

> steved.
>
>
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-nfs" in
> the body of a message to [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html

2011-03-04 06:10:28

by Masatake YAMATO

[permalink] [raw]
Subject: Re: [PATCH 1/2] Read /etc/exports.d/*.export as extra export files

Hi,

thank you for replying.

> On 03/03/2011 09:01 AM, Masatake YAMATO wrote:
>> No comment?
> Sorry about that... I was traveling for the couple weeks...
>
> Would you happen to have an example script on how
> this new feature would be used? I just want to run
> some quick tests...
>
> tia,
>
> steved.

Could you try following one?

# cd /tmp
# mkdir /tmp/alpha
# mkdir /tmp/beta
# mkdir /etc/exports.d
# mkdir /etc/exports.d
# echo '/tmp/alpha *(ro)' > /etc/exports.d/alpha.export
# echo '/tmp/beta *(ro)' > /etc/exports.d/beta.export
# /etc/init.d nfs restart

After above setting up, when you do `exportfs', following lines
may be included in the output:

/tmp/alpha <world>
/tmp/beta <world>


Masatake YAMATO

2011-03-05 21:42:07

by Steve Dickson

[permalink] [raw]
Subject: Re: [PATCH 1/2] Read /etc/exports.d/*.export as extra export files



On 03/05/2011 11:54 AM, Masatake YAMATO wrote:
> On Fri, 04 Mar 2011 11:21:54 -0500, Steve Dickson <[email protected]> wrote
>>
>>
>> On 03/04/2011 01:10 AM, Masatake YAMATO wrote:
>>> Hi,
>>>
>>> thank you for replying.
>> Again.. my apologies for taking so long...
>>
>>>
>>>> On 03/03/2011 09:01 AM, Masatake YAMATO wrote:
>>>>> No comment?
>>>> Sorry about that... I was traveling for the couple weeks...
>>>>
>>>> Would you happen to have an example script on how
>>>> this new feature would be used? I just want to run
>>>> some quick tests...
>>>>
>>>> tia,
>>>>
>>>> steved.
>>>
>>> Could you try following one?
>>>
>>> # cd /tmp
>>> # mkdir /tmp/alpha
>>> # mkdir /tmp/beta
>>> # mkdir /etc/exports.d
>>> # mkdir /etc/exports.d
>>> # echo '/tmp/alpha *(ro)' > /etc/exports.d/alpha.export
>>> # echo '/tmp/beta *(ro)' > /etc/exports.d/beta.export
>>> # /etc/init.d nfs restart
>>>
>>> After above setting up, when you do `exportfs', following lines
>>> may be included in the output:
>>>
>>> /tmp/alpha <world>
>>> /tmp/beta <world>
>> Question... Where is the race? Meaning who is reading the exports
>> file while its being modified?
>
> Sorry, I don't understand well. Are you talking about race condition
> introduced with my patch?
I thought you were doing this because some one trying to read
the exports as they were being updated... but after reading
your entire email I see I was mistaken...

>
>> The reason I ask is exporting (or re-exporting) pretty serial:
>>
>> exportfs read /etc/exports
>> exportfs writes the new exports to /var/lib/nfs/etab
>> mountd notices etab has changed and rereads its.
>> mountd flush the kernel cache cause the kernel to do upcalls to get the new exports.
>
> With my patch doesn't change match this sequence:
>
> (S1) exportfs read /etc/exports
> (S2) exportfs read /etc/exports.d/*.export
> (S3) exportfs writes the new exports to /var/lib/nfs/etab
> (S4) mountd notices etab has changed and rereads its.
> (S5) mountd flush the kernel cache cause the kernel to do upcalls to get the new exports.
>
> I've added (Sn) to make discussion easier. I've just added S2 stage.
>
>> So since exportfs command not a daemon I don't see why
>> cp exports.new /etc/exports && exportfs -arv
>>
>> isn't all that is needed. What am I missing?
>
> Consider the case when an user wants to add following entry to /etc/exports:
>
> '/tmp/alpha *(ro)'
>
> How one will do? Without my patch I image following sequence (sequence 1).
>
> cp /etc/exports exports.new
> echo '/tmp/alpha *(ro)' >> exports.new
> cp exports.new /etc/exports && exportfs -arv
>
> With my patch this sequence becomes simplified as (sequence 1'):
>
> echo '/tmp/alpha *(ro)' > /etc/exports.d/alpha.export
> exportfs -arv
>
> When duplicated entries must be considered the sequence 1 may become
> more complex.
>
>
> Next, consider removing the export entry from /etc/exports.
> Without my patch I image following sequence (sequence 2).
>
> cp /etc/exports exports.old
> grep -v '/tmp/alpha *(ro)' < exports.old > /etc/exports
> exportfs -arv
>
> With my patch this sequence becomes simplified as (sequence 2'):
> rm /etc/exports.d/alpha.export
> exportfs -arv
I understand and its a good idea.. thanks for the explanation...

>
>
> More background I'm thinking expanding the area of utilizing rpm package
> in system management. Consider installing an export entry to a system
> via rpm package. Without my patch you have to write down sequence 1
> to %post and sequence 2 to %postun of the spec file. With my patch
> you have to just put /etc/exports.d/alpha.export to %files section.
>
> This story of rpm is just my application. However, I thik my patch may be
> useful for other purposes.
I agree but I do have a question on the first patch which I will ask
in replay to that email...

Thanks again!

steved.

2011-03-06 01:51:13

by Jim Rees

[permalink] [raw]
Subject: Re: [PATCH 1/2] Read /etc/exports.d/*.export as extra export files

Steve Dickson wrote:

Now, I realize you added the ".export" explanation to the man page
but is there a particular reason why file in that directory have
to end with ".export"? Out of "easy of use" sake, should any
and all files that exist in that directory be expected to
be exports files?

I don't know if that's the best way to do it, but I think it would be useful
to have a way to keep files in the directory that don't get automatically
read. As an analogy, I have the following files in my /etc/init:

portmap.conf This is the real one that gets used
portmap.conf~ This is a backup file produced by emacs
portmap.conf-20100603 This is the file that came with my distro

Only the first one gets used, which is what I want, because it's the only
one ending in ".conf".

2011-03-06 06:11:29

by Masatake YAMATO

[permalink] [raw]
Subject: Re: [PATCH 1/2] Read /etc/exports.d/*.export as extra export files

On Sat, 5 Mar 2011 20:51:06 -0500, Jim Rees <[email protected]> wrote
> Steve Dickson wrote:
>
> Now, I realize you added the ".export" explanation to the man page
> but is there a particular reason why file in that directory have
> to end with ".export"? Out of "easy of use" sake, should any
> and all files that exist in that directory be expected to
> be exports files?
>
> I don't know if that's the best way to do it, but I think it would be useful
> to have a way to keep files in the directory that don't get automatically
> read. As an analogy, I have the following files in my /etc/init:
>
> portmap.conf This is the real one that gets used
> portmap.conf~ This is a backup file produced by emacs
> portmap.conf-20100603 This is the file that came with my distro
>
> Only the first one gets used, which is what I want, because it's the only
> one ending in ".conf".

Jim, thank you for explanation. He wrote what I'd like to write.

This technique is borrowed from util-linux-ng; libmount.so reads
only *.fstab under /etc/fstab.d.


In addition, ".export" suffix tells an editor which syntax highlighter
should be used when editing .export file:P

Masatake YAMATO

2011-03-07 14:14:09

by Steve Dickson

[permalink] [raw]
Subject: Re: [PATCH 1/2] Read /etc/exports.d/*.export as extra export files



On 03/07/2011 08:50 AM, Masatake YAMATO wrote:
>>
>>
>> On 03/07/2011 08:05 AM, Steve Dickson wrote:
>>>
>>>
>>> On 03/06/2011 01:11 AM, Masatake YAMATO wrote:
>>>> On Sat, 5 Mar 2011 20:51:06 -0500, Jim Rees <[email protected]> wrote
>>>>> Steve Dickson wrote:
>>>>>
>>>>> Now, I realize you added the ".export" explanation to the man page
>>>>> but is there a particular reason why file in that directory have
>>>>> to end with ".export"? Out of "easy of use" sake, should any
>>>>> and all files that exist in that directory be expected to
>>>>> be exports files?
>>>>>
>>>>> I don't know if that's the best way to do it, but I think it would be useful
>>>>> to have a way to keep files in the directory that don't get automatically
>>>>> read. As an analogy, I have the following files in my /etc/init:
>>>>>
>>>>> portmap.conf This is the real one that gets used
>>>>> portmap.conf~ This is a backup file produced by emacs
>>>>> portmap.conf-20100603 This is the file that came with my distro
>>>>>
>>>>> Only the first one gets used, which is what I want, because it's the only
>>>>> one ending in ".conf".
>>> This makes sense...
>>>
>>>>
>>>> Jim, thank you for explanation. He wrote what I'd like to write.
>>>>
>>>> This technique is borrowed from util-linux-ng; libmount.so reads
>>>> only *.fstab under /etc/fstab.d.
>>>>
>>>>
>>>> In addition, ".export" suffix tells an editor which syntax highlighter
>>>> should be used when editing .export file:P
>>> True... But I noticed the suffix that gvim looks for is ".exports"
>>> not ".export".
>>>
>>> What editor are you using and does it look for a ".export" by default?
>>>
>> After thinking about this a little longer, I think making the
>> suffix ".exports" does make sense. Along with the that being
>> the default syntax highlighter for gvim, more importantly, its
>> also the name of the man page, exports(5).
>
> I see. I didn't think what is the best suffix the file such deeply.
> Do I need to resubmit a patch for s/.export/.exports/g?
No... I'll take care of it...

steved.

2011-03-07 14:02:34

by Jim Rees

[permalink] [raw]
Subject: Re: [PATCH 1/2] Read /etc/exports.d/*.export as extra export files

Steve Dickson wrote:

True... But I noticed the suffix that gvim looks for is ".exports"
not ".export".

Is the exports file format so complicated that we need syntax highlighting?

2011-03-04 16:21:56

by Steve Dickson

[permalink] [raw]
Subject: Re: [PATCH 1/2] Read /etc/exports.d/*.export as extra export files



On 03/04/2011 01:10 AM, Masatake YAMATO wrote:
> Hi,
>
> thank you for replying.
Again.. my apologies for taking so long...

>
>> On 03/03/2011 09:01 AM, Masatake YAMATO wrote:
>>> No comment?
>> Sorry about that... I was traveling for the couple weeks...
>>
>> Would you happen to have an example script on how
>> this new feature would be used? I just want to run
>> some quick tests...
>>
>> tia,
>>
>> steved.
>
> Could you try following one?
>
> # cd /tmp
> # mkdir /tmp/alpha
> # mkdir /tmp/beta
> # mkdir /etc/exports.d
> # mkdir /etc/exports.d
> # echo '/tmp/alpha *(ro)' > /etc/exports.d/alpha.export
> # echo '/tmp/beta *(ro)' > /etc/exports.d/beta.export
> # /etc/init.d nfs restart
>
> After above setting up, when you do `exportfs', following lines
> may be included in the output:
>
> /tmp/alpha <world>
> /tmp/beta <world>
Question... Where is the race? Meaning who is reading the exports
file while its being modified?

The reason I ask is exporting (or re-exporting) pretty serial:

exportfs read /etc/exports
exportfs writes the new exports to /var/lib/nfs/etab
mountd notices etab has changed and rereads its.
mountd flush the kernel cache cause the kernel to do upcalls to get the new exports.

So since exportfs command not a daemon I don't see why
cp exports.new /etc/exports && exportfs -arv

isn't all that is needed. What am I missing?

steved.




2011-03-07 13:50:57

by Masatake YAMATO

[permalink] [raw]
Subject: Re: [PATCH 1/2] Read /etc/exports.d/*.export as extra export files

>
>
> On 03/07/2011 08:05 AM, Steve Dickson wrote:
>>
>>
>> On 03/06/2011 01:11 AM, Masatake YAMATO wrote:
>>> On Sat, 5 Mar 2011 20:51:06 -0500, Jim Rees <[email protected]> wrote
>>>> Steve Dickson wrote:
>>>>
>>>> Now, I realize you added the ".export" explanation to the man page
>>>> but is there a particular reason why file in that directory have
>>>> to end with ".export"? Out of "easy of use" sake, should any
>>>> and all files that exist in that directory be expected to
>>>> be exports files?
>>>>
>>>> I don't know if that's the best way to do it, but I think it would be useful
>>>> to have a way to keep files in the directory that don't get automatically
>>>> read. As an analogy, I have the following files in my /etc/init:
>>>>
>>>> portmap.conf This is the real one that gets used
>>>> portmap.conf~ This is a backup file produced by emacs
>>>> portmap.conf-20100603 This is the file that came with my distro
>>>>
>>>> Only the first one gets used, which is what I want, because it's the only
>>>> one ending in ".conf".
>> This makes sense...
>>
>>>
>>> Jim, thank you for explanation. He wrote what I'd like to write.
>>>
>>> This technique is borrowed from util-linux-ng; libmount.so reads
>>> only *.fstab under /etc/fstab.d.
>>>
>>>
>>> In addition, ".export" suffix tells an editor which syntax highlighter
>>> should be used when editing .export file:P
>> True... But I noticed the suffix that gvim looks for is ".exports"
>> not ".export".
>>
>> What editor are you using and does it look for a ".export" by default?
>>
> After thinking about this a little longer, I think making the
> suffix ".exports" does make sense. Along with the that being
> the default syntax highlighter for gvim, more importantly, its
> also the name of the man page, exports(5).

I see. I didn't think what is the best suffix the file such deeply.
Do I need to resubmit a patch for s/.export/.exports/g?

Masatake YAMATO

> steved.
> --
> To unsubscribe from this list: send the line "unsubscribe linux-nfs" in
> the body of a message to [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html


2011-03-07 14:27:16

by Masatake YAMATO

[permalink] [raw]
Subject: Re: [PATCH 1/2] Read /etc/exports.d/*.export as extra export files

>
>
> On 03/07/2011 08:50 AM, Masatake YAMATO wrote:
>>>
>>>
>>> On 03/07/2011 08:05 AM, Steve Dickson wrote:
>>>>
>>>>
>>>> On 03/06/2011 01:11 AM, Masatake YAMATO wrote:
>>>>> On Sat, 5 Mar 2011 20:51:06 -0500, Jim Rees <[email protected]> wrote
>>>>>> Steve Dickson wrote:
>>>>>>
>>>>>> Now, I realize you added the ".export" explanation to the man page
>>>>>> but is there a particular reason why file in that directory have
>>>>>> to end with ".export"? Out of "easy of use" sake, should any
>>>>>> and all files that exist in that directory be expected to
>>>>>> be exports files?
>>>>>>
>>>>>> I don't know if that's the best way to do it, but I think it would be useful
>>>>>> to have a way to keep files in the directory that don't get automatically
>>>>>> read. As an analogy, I have the following files in my /etc/init:
>>>>>>
>>>>>> portmap.conf This is the real one that gets used
>>>>>> portmap.conf~ This is a backup file produced by emacs
>>>>>> portmap.conf-20100603 This is the file that came with my distro
>>>>>>
>>>>>> Only the first one gets used, which is what I want, because it's the only
>>>>>> one ending in ".conf".
>>>> This makes sense...
>>>>
>>>>>
>>>>> Jim, thank you for explanation. He wrote what I'd like to write.
>>>>>
>>>>> This technique is borrowed from util-linux-ng; libmount.so reads
>>>>> only *.fstab under /etc/fstab.d.
>>>>>
>>>>>
>>>>> In addition, ".export" suffix tells an editor which syntax highlighter
>>>>> should be used when editing .export file:P
>>>> True... But I noticed the suffix that gvim looks for is ".exports"
>>>> not ".export".
>>>>
>>>> What editor are you using and does it look for a ".export" by default?
>>>>
>>> After thinking about this a little longer, I think making the
>>> suffix ".exports" does make sense. Along with the that being
>>> the default syntax highlighter for gvim, more importantly, its
>>> also the name of the man page, exports(5).
>>
>> I see. I didn't think what is the best suffix the file such deeply.
>> Do I need to resubmit a patch for s/.export/.exports/g?
> No... I'll take care of it...

Thanks. I'll watch the git repository.

Masatake YAMATO



> steved.
> --
> To unsubscribe from this list: send the line "unsubscribe linux-nfs" in
> the body of a message to [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html

2011-03-03 14:01:24

by Masatake YAMATO

[permalink] [raw]
Subject: Re: [PATCH 1/2] Read /etc/exports.d/*.export as extra export files

No comment?


Masatake YAMATO

> This patch adding a capability to read /etc/exports.d/*.export as
> extra export files to exportfs.
>
> If one wants to add or remove an export entry in a script, currently
> one may have to use sed or something tool for adding or removing the
> line for the entry in /etc/exports file.
>
> With the patch, adding and removing an entry from a script is much easier.
> cat<<EOF... or mv can be used for adding. rm can be used for removing.
>
>
> Signed-off-by: Masatake YAMATO <[email protected]>
> ---
> support/include/nfslib.h | 6 ++++
> utils/exportfs/exportfs.c | 59 ++++++++++++++++++++++++++++++++++++++++++++-
> 2 files changed, 64 insertions(+), 1 deletions(-)
>
> diff --git a/support/include/nfslib.h b/support/include/nfslib.h
> index 53ece0e..864aae2 100644
> --- a/support/include/nfslib.h
> +++ b/support/include/nfslib.h
> @@ -25,6 +25,12 @@
> #ifndef _PATH_EXPORTS
> #define _PATH_EXPORTS "/etc/exports"
> #endif
> +#ifndef _PATH_EXPORTS_D
> +#define _PATH_EXPORTS_D "/etc/exports.d"
> +#endif
> +#ifndef _EXT_EXPORT
> +#define _EXT_EXPORT ".export"
> +#endif
> #ifndef _PATH_IDMAPDCONF
> #define _PATH_IDMAPDCONF "/etc/idmapd.conf"
> #endif
> diff --git a/utils/exportfs/exportfs.c b/utils/exportfs/exportfs.c
> index b78957f..26d0504 100644
> --- a/utils/exportfs/exportfs.c
> +++ b/utils/exportfs/exportfs.c
> @@ -25,6 +25,7 @@
> #include <fcntl.h>
> #include <netdb.h>
> #include <errno.h>
> +#include <dirent.h>
>
> #include "sockaddr.h"
> #include "misc.h"
> @@ -41,6 +42,7 @@ static void error(nfs_export *exp, int err);
> static void usage(const char *progname);
> static void validate_export(nfs_export *exp);
> static int matchhostname(const char *hostname1, const char *hostname2);
> +static void export_d_read(const char *dname);
>
> int
> main(int argc, char **argv)
> @@ -127,8 +129,10 @@ main(int argc, char **argv)
> return 0;
> }
> }
> - if (f_export && ! f_ignore)
> + if (f_export && ! f_ignore) {
> export_read(_PATH_EXPORTS);
> + export_d_read(_PATH_EXPORTS_D);
> + }
> if (f_export) {
> if (f_all)
> export_all(f_verbose);
> @@ -485,6 +489,59 @@ out:
> return result;
> }
>
> +/* Based on mnt_table_parse_dir() in
> + util-linux-ng/shlibs/mount/src/tab_parse.c */
> +static void
> +export_d_read(const char *dname)
> +{
> + int n = 0, i;
> + struct dirent **namelist = NULL;
> +
> +
> + n = scandir(dname, &namelist, NULL, versionsort);
> + if (n < 0)
> + xlog(L_NOTICE, "scandir %s: %s\n", dname, strerror(errno));
> + else if (n == 0)
> + return;
> +
> + for (i = 0; i < n; i++) {
> + struct dirent *d = namelist[i];
> + size_t namesz;
> + char fname[PATH_MAX + 1];
> + int fname_len;
> +
> +
> + if (d->d_type != DT_UNKNOWN
> + && d->d_type != DT_REG
> + && d->d_type != DT_LNK)
> + continue;
> + if (*d->d_name == '.')
> + continue;
> +
> +#define _EXT_EXPORT_SIZ (sizeof(_EXT_EXPORT) - 1)
> + namesz = strlen(d->d_name);
> + if (!namesz
> + || namesz < _EXT_EXPORT_SIZ + 1
> + || strcmp(d->d_name + (namesz - _EXT_EXPORT_SIZ),
> + _EXT_EXPORT))
> + continue;
> +
> + fname_len = snprintf(fname, PATH_MAX +1, "%s/%s", dname, d->d_name);
> + if (fname_len > PATH_MAX) {
> + xlog(L_WARNING, "Too long file name: %s in %s\n", d->d_name, dname);
> + continue;
> + }
> +
> + export_read(fname);
> + }
> +
> + for (i = 0; i < n; i++)
> + free(namelist[i]);
> + free(namelist);
> +
> + return;
> +}
> +
> static char
> dumpopt(char c, char *fmt, ...)
> {
> --
> 1.7.4
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-nfs" in
> the body of a message to [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html

2011-03-03 17:50:20

by J. Bruce Fields

[permalink] [raw]
Subject: Re: [PATCH 1/2] Read /etc/exports.d/*.export as extra export files

On Thu, Mar 03, 2011 at 04:26:41PM +0100, Ferenc Wagner wrote:
> Masatake YAMATO <[email protected]> writes:
>
> > No comment?
>
> I like the idea and find the approach sane, but I'm just a user.

I don't see any obvious problem; Steve's call.

--b.