nfs-utils: Improving NFS re-export wrt. crossmnt
Subsystems (2)
v2 cover nfs-utils: Improving NFS re-export wrt. crossmnt
[Resending this series because I got to git add two header files.]
After a longer hiatus I'm sending the next iteration of my re-export improvement patch series. While the kernel side is upstream since v6.2, the nfs-utils parts are still missing.
This patch series aims to solve this.
The core idea is adding new export option, reeport=
Using reexport= it is possible to mark an export entry in the exports file explicitly as NFS re-export and select a strategy on how unique identifiers should be provided. This makes the crossmnt feature work in the re-export case.
Currently two strategies are supported, "auto-fsidnum" and "predefined-fsidnum".
In my earlier series a sqlite database was mandatory to keep track of generated fsids.
This series follows a different approach, instead of directly using sqlite in all nfs-utils components (linking libsqlite), a new deamon manages the database, fsidd.
fsidd offers a simple (but stupid?) text based interface over a unix domain socket which can be queried by mountd, exportfs, etc. for fsidnums. The main idea behind fsidd is allowing users to implement their own fsidd which keeps global state across load balancers.
I'm still not happy with fsidd, there is room for improvement but first I'd like to know whether you like or hate this approach.
A typical export entry on a re-exporting server looks like:
/nfs *(rw,no_root_squash,no_subtree_check,crossmnt,reexport=auto-fsidnum)
reexport=auto-fsidnum will automatically assign an fsid= to /nfs and all uncovered subvolumes.
Changes since v1, https://lore.kernel.org/linux-nfs/[email protected]/
- Factor out Sqlite and put it into a daemon
- Add fsidd
- Basically re-implemented the patch series
- Lot's of fixes (e.g. nfs v4 root export)
Richard Weinberger (2):
export: Add reexport= option
Implement fsidd
configure.ac | 1 + support/Makefile.am | 2 +- support/export/Makefile.am | 2 + support/export/cache.c | 74 ++++++- support/export/export.c | 27 ++- support/include/nfslib.h | 1 + support/nfs/Makefile.am | 1 + support/nfs/exports.c | 62 ++++++ support/reexport/Makefile.am | 18 ++ support/reexport/backend_sqlite.c | 267 +++++++++++++++++++++++ support/reexport/fsidd.c | 198 +++++++++++++++++ support/reexport/reexport.c | 327 ++++++++++++++++++++++++++++ support/reexport/reexport.h | 18 ++ support/reexport/reexport_backend.h | 47 ++++ systemd/Makefile.am | 2 + systemd/fsidd.service | 9 + utils/exportd/Makefile.am | 6 +- utils/exportd/exportd.c | 5 + utils/exportfs/Makefile.am | 3 + utils/exportfs/exportfs.c | 11 + utils/exportfs/exports.man | 31 +++ utils/mount/Makefile.am | 3 +- utils/mountd/Makefile.am | 2 + 23 files changed, 1106 insertions(+), 11 deletions(-) create mode 100644 support/reexport/Makefile.am create mode 100644 support/reexport/backend_sqlite.c create mode 100644 support/reexport/fsidd.c create mode 100644 support/reexport/reexport.c create mode 100644 support/reexport/reexport.h create mode 100644 support/reexport/reexport_backend.h create mode 100644 systemd/fsidd.service
Signature · 1 line
2.31.1
PATCH v2 1/2 export: Add reexport= option
When re-exporting a NFS volume it is mandatory to specify either a UUID or numerical fsid= option because nfsd is unable to derive an identifier on its own.
For NFS cross mounts this becomes a problem because nfsd also needs an identifier for every crossed mount.
A common workaround is stating every single subvolume in the exports list too.
But this defeats the purpose of the crossmnt option and is tedious.
This is where the reexport= tries to help.
It offers various strategies to automatically derive a identifier for NFS volumes and sub volumes.
Currently two strategies are implemented:
1. auto-fsidnum
In this mode mountd/exportd will create a new numerical fsid for a NFS volume and subvolume. The numbers are stored in a database, via fsidd, such that the server will always use the same fsid. The entry in the exports file allowed to skip the fsid= option but stating a UUID is allowed, if needed.
This mode has the obvious downside that load balancing is by default not possible since multiple re-exporting NFS servers would generate different ids.
It is possible if all load balancers use the same database. This can be achieved by using nfs-utils' fsidd and placing it's sqlit database on a network share which supports file locks or by implementing your own fsidd which is able to provide consistent fsids across multiple re-exporting nfs servers.
2. predefined-fsidnum
This mode works just like auto-fsidnum but does not generate ids for you. It helps in the load balancing case. A system administrator has to manually maintain the database and install it on all re-exporting NFS servers. If you have a massive amount of subvolumes this mode will help because you don't have to bloat the exports list.
--- configure.ac | 1 + support/Makefile.am | 2 +- support/export/Makefile.am | 2 + support/export/cache.c | 74 +++++++- support/export/export.c | 27 ++- support/include/nfslib.h | 1 + support/nfs/Makefile.am | 1 + support/nfs/exports.c | 62 +++++++ support/reexport/Makefile.am | 6 + support/reexport/reexport.c | 327 +++++++++++++++++++++++++++++++++++ support/reexport/reexport.h | 18 ++ systemd/Makefile.am | 2 + utils/exportd/Makefile.am | 6 +- utils/exportd/exportd.c | 5 + utils/exportfs/Makefile.am | 3 + utils/exportfs/exportfs.c | 11 ++ utils/exportfs/exports.man | 31 ++++ utils/mount/Makefile.am | 3 +- utils/mountd/Makefile.am | 2 + 19 files changed, 573 insertions(+), 11 deletions(-) create mode 100644 support/reexport/Makefile.am create mode 100644 support/reexport/reexport.c create mode 100644 support/reexport/reexport.h
configure.ac +1 -0
@@ -717,6 +717,7 @@ AC_CONFIG_FILES([ support/nsm/Makefile support/nfsidmap/Makefile support/nfsidmap/libnfsidmap.pc + support/reexport/Makefile tools/Makefile tools/locktest/Makefile tools/nlmtest/Makefile
support/Makefile.am +1 -1
@@ -10,7 +10,7 @@ if CONFIG_JUNCTION OPTDIRS += junction endif -SUBDIRS = export include misc nfs nsm $(OPTDIRS) +SUBDIRS = export include misc nfs nsm reexport $(OPTDIRS) MAINTAINERCLEANFILES = Makefile.in
support/export/Makefile.am +2 -0
@@ -14,6 +14,8 @@ libexport_a_SOURCES = client.c export.c hostname.c \ xtab.c mount_clnt.c mount_xdr.c \ cache.c auth.c v4root.c fsloc.c \ v4clients.c +libexport_a_CPPFLAGS = $(AM_CPPFLAGS) $(CPPFLAGS) -I$(top_srcdir)/support/reexport + BUILT_SOURCES = $(GENFILES) noinst_HEADERS = mount.h
support/export/cache.c +68 -6
135 lines not on this page · raw message
support/export/export.c +25 -2
@@ -25,6 +25,7 @@#include "exportfs.h" #include "nfsd_path.h" #include "xlog.h" +#include "reexport.h" exp_hash_table exportlist[MCL_MAXTYPES ] = {{NULL , {{NULL ,NULL }, }}, };static int export_hash (char *);
@@ -115,6 +116,7 @@ export_read(char *fname, int ignore_hosts)nfs_export *exp;int volumes =0 ; +int reexport_found =0 ;setexportent (fname,"r" );while ((eep =getexportent (0 ,1 )) !=NULL ) {
@@ -126,7 +128,25 @@ export_read(char *fname, int ignore_hosts) }else warn_duplicated_exports (exp, eep); + +if (eep->e_reexport) + reexport_found =1 ; + } + +if (reexport_found) { +for (int i =0 ; i <MCL_MAXTYPES ; i++) { +for (exp = exportlist[i].p_head; exp; exp = exp->m_next) { +if (exp->m_export.e_reexport) +continue ; + +if (exp->m_export.e_flags &NFSEXP_FSID ) { +xlog (L_ERROR ,"When a reexport= option is present no manully assigned numerical fsid= options are allowed" ); +return -1 ; + } + } + } } +endexportent ();return volumes;
@@ -147,7 +167,7 @@ export_d_read(const char *dname, int ignore_hosts)int n =0 , i;struct dirent **namelist =NULL ;int volumes =0 ; - +int num_exports; n =scandir (dname, &namelist,NULL , versionsort);if (n <0 ) {
@@ -186,7 +206,10 @@ export_d_read(const char *dname, int ignore_hosts)continue ; } - volumes +=export_read (fname, ignore_hosts); + num_exports =export_read (fname, ignore_hosts); +if (num_exports <0 ) +return -1 ; + volumes += num_exports; }for (i =0 ; i < n; i++)
support/include/nfslib.h +1 -0
@@ -85,6 +85,7 @@ struct exportent {struct sec_entry e_secinfo[SECFLAVOR_COUNT +1 ];unsigned int e_ttl;char * e_realpath; +int e_reexport; };struct rmtabent {
support/nfs/Makefile.am +1 -0
@@ -9,6 +9,7 @@ libnfs_la_SOURCES = exports.c rmtab.c xio.c rpcmisc.c rpcdispatch.c \ svc_socket.c cacheio.c closeall.c nfs_mntent.c \ svc_create.c atomicio.c strlcat.c strlcpy.c libnfs_la_LIBADD = libnfsconf.la +libnfs_la_CPPFLAGS = $(AM_CPPFLAGS) $(CPPFLAGS) -I$(top_srcdir)/support/reexport libnfsconf_la_SOURCES = conffile.c xlog.c
support/nfs/exports.c +62 -0
98 lines not on this page · raw message
support/reexport/Makefile.am new file +6 -0
@@ -0,0 +1,6 @@ +## Process this file with automake to produce Makefile.in + +noinst_LIBRARIES = libreexport.a +libreexport_a_SOURCES = reexport.c + +MAINTAINERCLEANFILES = Makefile.in
support/reexport/reexport.c new file +327 -0
327 lines not on this page · raw message
support/reexport/reexport.h new file +18 -0
@@ -0,0 +1,18 @@ +#ifndef REEXPORT_H +#define REEXPORT_H + +enum { +REEXP_NONE =0 , +REEXP_AUTO_FSIDNUM , +REEXP_PREDEFINED_FSIDNUM , +}; + +int reexpdb_init (void ); +void reexpdb_destroy (void ); +int reexpdb_fsidnum_by_path (char *path,uint32_t *fsidnum,int may_create); +int reexpdb_apply_reexport_settings (struct exportent *ep,char *flname,int flline); +void reexpdb_uncover_subvolume (uint32_t fsidnum); + +#define FSID_SOCKET_NAME "fsid.sock" + +#endif /* REEXPORT_H */
systemd/Makefile.am +2 -0
@@ -70,8 +70,10 @@ rpc_pipefs_generator_SOURCES = $(COMMON_SRCS) rpc-pipefs-generator.c nfs_server_generator_LDADD = ../support/export/libexport.a \ ../support/nfs/libnfs.la \ ../support/misc/libmisc.a \ + ../support/reexport/libreexport.a \ $(LIBPTHREAD) + rpc_pipefs_generator_LDADD = ../support/nfs/libnfs.la if INSTALL_SYSTEMD
utils/exportd/Makefile.am +5 -1
@@ -16,11 +16,15 @@ exportd_SOURCES = exportd.c exportd_LDADD = ../../support/export/libexport.a \ ../../support/nfs/libnfs.la \ ../../support/misc/libmisc.a \ - $(OPTLIBS) $(LIBBLKID) $(LIBPTHREAD) -luuid + ../support/reexport/libreexport.a \ + $(OPTLIBS) $(LIBBLKID) $(LIBPTHREAD) \ + -luuid exportd_CPPFLAGS = $(AM_CPPFLAGS) $(CPPFLAGS) \ -I$(top_srcdir)/support/export +exportd_CPPFLAGS += -I$(top_srcdir)/support/reexport + MAINTAINERCLEANFILES = Makefile.in #######################################################################
utils/exportd/exportd.c +5 -0
@@ -22,6 +22,7 @@#include "conffile.h" #include "exportfs.h" #include "export.h" +#include "reexport.h" extern void my_svc_run (void );
@@ -296,6 +297,10 @@ main(int argc, char **argv)/* Open files now to avoid sharing descriptors among forked processes */ cache_open ();v4clients_init (); +if (reexpdb_init () !=0 ) { +xlog (L_ERROR ,"%s: Failed to init reexport database" , __func__); +exit (1 ); + }/* Process incoming upcalls */ cache_process_loop ();
utils/exportfs/Makefile.am +3 -0
@@ -10,6 +10,9 @@ exportfs_SOURCES = exportfs.c exportfs_LDADD = ../../support/export/libexport.a \ ../../support/nfs/libnfs.la \ ../../support/misc/libmisc.a \ + ../../support/reexport/libreexport.a \ $(LIBWRAP) $(LIBNSL) $(LIBPTHREAD) +exportfs_CPPFLAGS = $(AM_CPPFLAGS) $(CPPFLAGS) -I$(top_srcdir)/support/reexport + MAINTAINERCLEANFILES = Makefile.in
utils/exportfs/exportfs.c +11 -0
@@ -38,6 +38,7 @@#include "exportfs.h" #include "xlog.h" #include "conffile.h" +#include "reexport.h" static void export_all (int verbose);static void exportfs (char *arg,char *options,int verbose);
@@ -719,6 +720,16 @@ dump(int verbose, int export_format) c =dumpopt (c,"fsid=%d" , ep->e_fsid);if (ep->e_uuid) c =dumpopt (c,"fsid=%s" , ep->e_uuid); +if (ep->e_reexport) { +switch (ep->e_reexport) { +case REEXP_AUTO_FSIDNUM : + c =dumpopt (c,"reexport=%s" ,"auto-fsidnum" ); +break ; +case REEXP_PREDEFINED_FSIDNUM : + c =dumpopt (c,"reexport=%s" ,"predefined-fsidnum" ); +break ; + } + }if (ep->e_mountpoint) c = dumpopt(c, "mountpoint%s%s", ep->e_mountpoint[0]?"=":"",
utils/exportfs/exports.man +31 -0
@@ -420,6 +420,37 @@ will only work if all clients use a consistent security policy. Note that early kernels did not support this export option, and instead enabled security labels by default. +.TP +.IR reexport= auto-fsidnum|predefined-fsidnum +This option helps when a NFS share is re-exported. Since the NFS server +needs a unique identifier for each exported filesystem and a NFS share +cannot provide such, usually a manual fsid is needed. +As soon +.IR crossmnt +is used manually assigning fsid won't work anymore. This is where this +option becomes handy. It will automatically assign a numerical fsid +to exported NFS shares. The fsid and path relations are stored in a SQLite +database. If +.IR auto-fsidnum +is selected, the fsid is also autmatically allocated. +.IR predefined-fsidnum +assumes pre-allocated fsid numbers and will just look them up. +This option depends also on the kernel, you will need at least kernel version +5.19. +Since +.IR reexport= +can automatically allocate and assign numerical fsids, it is no longer possible +to have numerical fsids in other exports as soon this option is used in at least +one export entry. + +The association between fsid numbers and paths is stored in a SQLite database. +Don't edit or remove the database unless you know exactly what you're doing. +.IR predefined-fsidnum +is useful when you have used +.IR auto-fsidnum +before and don't want further entries stored. + + .SS User ID Mapping .PP .B nfsd
utils/mount/Makefile.am +2 -1
@@ -29,8 +29,9 @@ endif mount_nfs_LDADD = ../../support/nfs/libnfs.la \ ../../support/export/libexport.a \ + ../../support/reexport/libreexport.a \ ../../support/misc/libmisc.a \ - $(LIBTIRPC) + $(LIBTIRPC) $(LIBPTHREAD) mount_nfs_SOURCES = $(mount_common)
utils/mountd/Makefile.am +2 -0
@@ -17,9 +17,11 @@ mountd_SOURCES = mountd.c mount_dispatch.c rmtab.c \ mountd_LDADD = ../../support/export/libexport.a \ ../../support/nfs/libnfs.la \ ../../support/misc/libmisc.a \ + ../../support/reexport/libreexport.a \ $(OPTLIBS) \ $(LIBBSD) $(LIBWRAP) $(LIBNSL) $(LIBBLKID) -luuid $(LIBTIRPC) \ $(LIBPTHREAD) + mountd_CPPFLAGS = $(AM_CPPFLAGS) $(CPPFLAGS) \ -I$(top_builddir)/support/include \ -I$(top_srcdir)/support/export
Signature · 1 line
2.31.1
PATCH v2 2/2 Implement fsidd
In reply to Richard WeinbergerThe file system id service is a small daemon which serves and creates fsids by a given path. Currently it supports only on backend, a sqlite database.
Every nfs related service, such as mountd or exportfs can query it using a local domain socket.
--- support/reexport/Makefile.am | 12 ++ support/reexport/backend_sqlite.c | 267 ++++++++++++++++++++++++++++ support/reexport/fsidd.c | 198 +++++++++++++++++++++ support/reexport/reexport_backend.h | 47 +++++ systemd/fsidd.service | 9 + 5 files changed, 533 insertions(+) create mode 100644 support/reexport/backend_sqlite.c create mode 100644 support/reexport/fsidd.c create mode 100644 support/reexport/reexport_backend.h create mode 100644 systemd/fsidd.service
support/reexport/Makefile.am +12 -0
@@ -3,4 +3,16 @@ noinst_LIBRARIES = libreexport.a libreexport_a_SOURCES = reexport.c +sbin_PROGRAMS = fsidd + +fsidd_SOURCES = fsidd.c backend_sqlite.c + +fsidd_LDADD = ../../support/misc/libmisc.a \ + ../../support/nfs/libnfs.la \ + $(LIBPTHREAD) $(LIBEVENT) $(LIBSQLITE) \ + $(OPTLIBS) + +fsidd_CPPFLAGS = $(AM_CPPFLAGS) $(CPPFLAGS) \ + -I$(top_builddir)/support/include + MAINTAINERCLEANFILES = Makefile.in
support/reexport/backend_sqlite.c new file +267 -0
267 lines not on this page · raw message
support/reexport/fsidd.c new file +198 -0
198 lines not on this page · raw message
support/reexport/reexport_backend.h new file +47 -0
47 lines not on this page · raw message
systemd/fsidd.service new file +9 -0
@@ -0,0 +1,9 @@ +[Unit] +Description=Filesystem ID service for NFS re-exporting +DefaultDependencies=no +Conflicts=umount.target +Before=nfs-server.service + +[Service] +Type=simple +ExecStart=/usr/sbin/fsidd
Signature · 1 line
2.31.1
Quoted 1 line · Richard Weinberger
[Resending this series because I got to git add two header files.]
My apologies for taking so long to get to this! And Thank you for this work... But there is a
few issues ;-)
Quoted 66 lines
After a longer hiatus I'm sending the next iteration of my re-export improvement patch series. While the kernel side is upstream since v6.2, the nfs-utils parts are still missing.
This patch series aims to solve this.The core idea is adding new export option, reeport=
Using reexport= it is possible to mark an export entry in the exports file explicitly as NFS re-export and select a strategy on how unique identifiers should be provided. This makes the crossmnt feature work in the re-export case.
Currently two strategies are supported, "auto-fsidnum" and "predefined-fsidnum".In my earlier series a sqlite database was mandatory to keep track of generated fsids.
This series follows a different approach, instead of directly using sqlite in all nfs-utils components (linking libsqlite), a new deamon manages the database, fsidd.
fsidd offers a simple (but stupid?) text based interface over a unix domain socket which can be queried by mountd, exportfs, etc. for fsidnums. The main idea behind fsidd is allowing users to implement their own fsidd which keeps global state across load balancers.
I'm still not happy with fsidd, there is room for improvement but first I'd like to know whether you like or hate this approach.A typical export entry on a re-exporting server looks like:
/nfs *(rw,no_root_squash,no_subtree_check,crossmnt,reexport=auto-fsidnum)
reexport=auto-fsidnum will automatically assign an fsid= to /nfs and all uncovered subvolumes.Changes since v1, https://lore.kernel.org/linux-nfs/[email protected]/
- Factor out Sqlite and put it into a daemon
- Add fsidd
- Basically re-implemented the patch series
- Lot's of fixes (e.g. nfs v4 root export)Richard Weinberger (2):
export: Add reexport= option
Implement fsiddconfigure.ac | 1 + support/Makefile.am | 2 +- support/export/Makefile.am | 2 + support/export/cache.c | 74 ++++++- support/export/export.c | 27 ++- support/include/nfslib.h | 1 + support/nfs/Makefile.am | 1 + support/nfs/exports.c | 62 ++++++ support/reexport/Makefile.am | 18 ++ support/reexport/backend_sqlite.c | 267 +++++++++++++++++++++++ support/reexport/fsidd.c | 198 +++++++++++++++++ support/reexport/reexport.c | 327 ++++++++++++++++++++++++++++ support/reexport/reexport.h | 18 ++ support/reexport/reexport_backend.h | 47 ++++ systemd/Makefile.am | 2 + systemd/fsidd.service | 9 + utils/exportd/Makefile.am | 6 +- utils/exportd/exportd.c | 5 + utils/exportfs/Makefile.am | 3 + utils/exportfs/exportfs.c | 11 + utils/exportfs/exports.man | 31 +++ utils/mount/Makefile.am | 3 +- utils/mountd/Makefile.am | 2 + 23 files changed, 1106 insertions(+), 11 deletions(-)
Quoted 8 lines
create mode 100644 support/reexport/Makefile.am create mode 100644
support/reexport/backend_sqlite.ccreate mode 100644support/reexport/fsidd.ccreate mode 100644support/reexport/reexport.ccreate mode 100644support/reexport/reexport.hcreate mode 100644support/reexport/reexport_backend.hcreate mode 100644 systemd/fsidd.service
These patch does not apply cleanly on Chuck's TLS patches, not something you could have voided and the fix is minor... But!
Then the first patch does not compile without
the second patch due to a missing header file.
When the second patch is applied the compile
breaks in exportd code:
make[2]: *** No rule to make target
'../support/reexport/libreexport.a', needed by 'exportd'. Stop.
The first patch is way to big for debugging and reading... IMO.
Maybe the exportd, exportfs, and mount changes be put in their own patches and maybe the reexport command can be separated out from the rest of support/ changes although that might be more difficult.
Not clear how you can break up the second patch other than moving reexport_backend.h into the first patch so it compiles...
I just committed Chuck's TLS patch (tag: nfs-utils-2-6-3-rc8) So if you could rebase your patches to the head of my repo that would great, with the above changes.
I'll be very motivate get these changes in for the upcoming virtual bakeathon starting a week from Monday (Apr 24). The detail are here [1]...
I'm hopeful you will be attending and setting a server for us to test against.
Thanks again for all this work!!
steved.
----- Ursprüngliche Mail -----
Quoted 2 lines
Von: "Steve Dickson" <[email protected]>
My apologies for taking so long to get to this!
No problem. :-)
Quoted 19 lines
These patch does not apply cleanly on Chuck's TLS patches, not something you could have voided and the fix is minor... But!
Then the first patch does not compile without
the second patch due to a missing header file.When the second patch is applied the compile
breaks in exportd code:
make[2]: *** No rule to make target
'../support/reexport/libreexport.a', needed by 'exportd'. Stop.The first patch is way to big for debugging and reading... IMO.
Maybe the exportd, exportfs, and mount changes be put in their own patches and maybe the reexport command can be separated out from the rest of support/ changes although that might be more difficult.
Quoted 7 lines
Not clear how you can break up the second patch other than moving
reexport_backend.hinto the first patch so it compiles...I just committed Chuck's TLS patch (tag: nfs-utils-2-6-3-rc8) So if you could rebase your patches to the head of my repo that would great, with the above changes.
I just rebased the whole series and spitted into multiple patches. Every single patch builds now, sorry for that.
Quoted 6 lines
I'll be very motivate get these changes in for the upcoming virtual bakeathon starting a week from Monday (Apr 24). The detail are here [1]...
I'm hopeful you will be attending and setting a server for us to test against.
I'll try hard to attend! :-)
Thanks,
//richard