nfs-server-generator: avoid using external services.
Subsystems (2)
PATCH 1/1 nfs-server-generator: avoid using external services.
nfs-server-generator is run very early when a lot of services are not yet started, so it mustn't depend on them. Currently it can try to use hostname lookup and syslog.
Hostname-lookup is not needed, as we don't use the host issue, and sending message to stderr is sufficient for the generator.
Disabling syslog is easy - call a function that sets a static variable.
Disabling hostname lookup isn't quite so easy, so add a static variable which can be set to disable it.
---
hi,
I contemplated passing another arg to export_read() and export_d_read() to resolve this, but it didn't seem worth it.
Is this approach OK to people?
Thanks,
NeilBrown
support/export/export.c | 12 ++++++++++-- support/include/exportfs.h | 1 + systemd/nfs-server-generator.c | 4 ++++ 3 files changed, 15 insertions(+), 2 deletions(-)
support/export/export.c +10 -2
@@ -67,6 +67,14 @@ static void warn_duplicated_exports(nfs_export *exp, struct exportent *eep) } } +static int assume_canonical =0 ; + +void +export_avoid_host_lookup (int i) +{ + assume_canonical = i; +} +/** * export_read - read entries from /etc/exports * @fname: name of file to read from
@@ -83,9 +91,9 @@ export_read(char *fname)setexportent (fname,"r" );while ((eep =getexportent (0 ,1 )) !=NULL ) { - exp =export_lookup (eep->e_hostname, eep->e_path,0 ); + exp =export_lookup (eep->e_hostname, eep->e_path, assume_canonical);if (!exp) { -if (export_create (eep,0 )) +if (export_create (eep, assume_canonical))/* possible complaints already logged */ volumes++; }
support/include/exportfs.h +1 -0
@@ -134,6 +134,7 @@ struct addrinfo * client_resolve(const struct sockaddr *sap);int client_member (const char *client,const char *name); +void export_avoid_host_lookup (int i);int export_read (char *fname);int export_d_read (const char *dname);void export_reset (nfs_export *);
systemd/nfs-server-generator.c +4 -0
@@ -93,6 +93,10 @@ int main(int argc, char *argv[])FILE *f, *fstab;struct mntent *mnt; +/* Avoid using any external services */ +xlog_syslog (0 ); +export_avoid_host_lookup (1 ); +if (argc !=4 || argv[1 ][0 ] !='/' ) {fprintf (stderr,"nfs-server-generator: create systemd dependencies for nfs-server\n" );fprintf (stderr,"Usage: normal-dir early-dir late-dir\n" );
Signature · 1 line
2.10.0
Hello,
Quoted 13 lines · NeilBrown
nfs-server-generator is run very early when a lot of services are not yet started, so it mustn't depend on them. Currently it can try to use hostname lookup and syslog.
Hostname-lookup is not needed, as we don't use the host issue, and sending message to stderr is sufficient for the generator.
Disabling syslog is easy - call a function that sets a static variable.
Disabling hostname lookup isn't quite so easy, so add a static variable which can be set to disable it.
Quoted 8 lines
Signed-off-by NeilBrown <[email protected]>---
hi,
I contemplated passing another arg toexport_read()andexport_d_read()to resolve this, but it didn't seem worth it.Is this approach OK to people?
It's not the most eloquent interface I've ever seen... ;-)
What are the failures this is fixing? When a hostname lookup is done what happens? Failure hangs stopping the server from coming up?
Quoted 15 lines
Thanks,
NeilBrownsupport/export/export.c | 12 ++++++++++-- support/include/exportfs.h | 1 + systemd/nfs-server-generator.c | 4 ++++ 3 files changed, 15 insertions(+), 2 deletions(-)support/export/export.c +0
-0
support/export/export.c static void warn_duplicated_exports(nfs_export *exp, struct exportent *eep) · line 68
Quoted 2 lines
support/export/export.c +0
-0@@ -67,6 +67,14 @@ static void warn_duplicated_exports(nfs_export *exp, struct exportent *eep) } }
If we do have to stay with this approach, I definitely think comment explaining why its needed and what it does.
Finally, on an unrelated issue I'm seeing SELinux preventing nfs-server-generator from accessing nfs-server.service.d/order-with-mounts.conf because of a labeling issue. I guess the label should be nfsd_unit_file_t not systemd_unit_file_t
steved.
Quoted 52 lines
support/export/export.c +10
-2+static int assume_canonical =0 ; + +void +export_avoid_host_lookup (int i) +{ + assume_canonical = i; +} +/** * export_read - read entries from /etc/exports * @fname: name of file to read from @@ -83,9 +91,9 @@ export_read(char *fname)setexportent (fname,"r" );while ((eep =getexportent (0 ,1 )) !=NULL ) { - exp =export_lookup (eep->e_hostname, eep->e_path,0 ); + exp =export_lookup (eep->e_hostname, eep->e_path, assume_canonical);if (!exp) { -if (export_create (eep,0 )) +if (export_create (eep, assume_canonical))/* possible complaints already logged */ volumes++; }support/include/exportfs.h +1
-0@@ -134,6 +134,7 @@ struct addrinfo * client_resolve(const struct sockaddr *sap);int client_member (const char *client,const char *name); +void export_avoid_host_lookup (int i);int export_read (char *fname);int export_d_read (const char *dname);void export_reset (nfs_export *);systemd/nfs-server-generator.c +4
-0@@ -93,6 +93,10 @@ int main(int argc, char *argv[])FILE *f, *fstab;struct mntent *mnt; +/* Avoid using any external services */ +xlog_syslog (0 ); +export_avoid_host_lookup (1 ); +if (argc !=4 || argv[1 ][0 ] !='/' ) {fprintf (stderr,"nfs-server-generator: create systemd dependencies for nfs-server\n" );fprintf (stderr,"Usage: normal-dir early-dir late-dir\n" );
Quoted 23 lines · Steve Dickson
Hello,
Quoted 20 lines · NeilBrown
nfs-server-generator is run very early when a lot of services are not yet started, so it mustn't depend on them. Currently it can try to use hostname lookup and syslog.
Hostname-lookup is not needed, as we don't use the host issue, and sending message to stderr is sufficient for the generator.
Disabling syslog is easy - call a function that sets a static variable.
Disabling hostname lookup isn't quite so easy, so add a static variable which can be set to disable it.
Signed-off-by NeilBrown <[email protected]>---
hi,
I contemplated passing another arg toexport_read()andexport_d_read()to resolve this, but it didn't seem worth it.
Quoted 7 lines
Quoted 1 line
Is this approach OK to people?
It's not the most eloquent interface I've ever seen... ;-)
What are the failures this is fixing? When a hostname lookup is done what happens? Failure hangs stopping the server from coming up?
I never actually reproduced it myself, but I think that when hostname lookup failed (possibly after a timeout) it tried to log an error via syslog and writing to syslog blocked indefinitely.
The systemd.generator manpage explicitly rules out trying to talk to syslog.
Quoted 12 lines
Quoted 12 lines
Thanks,
NeilBrownsupport/export/export.c | 12 ++++++++++-- support/include/exportfs.h | 1 + systemd/nfs-server-generator.c | 4 ++++ 3 files changed, 15 insertions(+), 2 deletions(-)
Quoted 10 lines
support/export/export.c static void warn_duplicated_exports(nfs_export *exp, struct exportent *eep) · line 68
Quoted 7 lines
support/export/export.c +0
-0@@ -67,6 +67,14 @@ static void warn_duplicated_exports(nfs_export *exp, struct exportent *eep) } }If we do have to stay with this approach, I definitely think comment explaining why its needed and what it does.
That's sensible. I'll resend with some nice friendly comments.
Quoted 6 lines
Finally, on an unrelated issue I'm seeing SELinux preventing nfs-server-generator from accessing
nfs-server.service.d/order-with-mounts.confbecause of a labeling issue. I guess the label should benfsd_unit_file_tnotsystemd_unit_file_t
I wouldn't know about that :-(
Thanks,
NeilBrown
Quoted 33 lines · NeilBrown
Quoted 23 lines · Steve Dickson
Hello,
Quoted 20 lines · NeilBrown
nfs-server-generator is run very early when a lot of services are not yet started, so it mustn't depend on them. Currently it can try to use hostname lookup and syslog.
Hostname-lookup is not needed, as we don't use the host issue, and sending message to stderr is sufficient for the generator.
Disabling syslog is easy - call a function that sets a static variable.
Disabling hostname lookup isn't quite so easy, so add a static variable which can be set to disable it.
Signed-off-by NeilBrown <[email protected]>---
hi,
I contemplated passing another arg toexport_read()andexport_d_read()to resolve this, but it didn't seem worth it.Quoted 7 lines
Quoted 1 line
Is this approach OK to people?
It's not the most eloquent interface I've ever seen... ;-)
What are the failures this is fixing? When a hostname lookup is done what happens? Failure hangs stopping the server from coming up?
Quoted 5 lines
I never actually reproduced it myself, but I think that when hostname lookup failed (possibly after a timeout) it tried to log an error via syslog and writing to syslog blocked indefinitely.
The systemd.generator manpage explicitly rules out trying to talk to syslog.
This makes sense...
Quoted 25 lines
Quoted 14 lines
Quoted 14 lines
Thanks,
NeilBrownsupport/export/export.c | 12 ++++++++++-- support/include/exportfs.h | 1 + systemd/nfs-server-generator.c | 4 ++++ 3 files changed, 15 insertions(+), 2 deletions(-)Quoted 10 lines
support/export/export.c static void warn_duplicated_exports(nfs_export *exp, struct exportent *eep) · line 68
Quoted 7 lines
support/export/export.c +0
-0@@ -67,6 +67,14 @@ static void warn_duplicated_exports(nfs_export *exp, struct exportent *eep) } }If we do have to stay with this approach, I definitely think comment explaining why its needed and what it does.
Quoted 1 line
That's sensible. I'll resend with some nice friendly comments.
Thanks!
Quoted 9 lines
Quoted 7 lines
Finally, on an unrelated issue I'm seeing SELinux preventing nfs-server-generator from accessing
nfs-server.service.d/order-with-mounts.confbecause of a labeling issue. I guess the label should benfsd_unit_file_tnotsystemd_unit_file_tI wouldn't know about that :-(
I'll figure this out...
steved.
Quoted 4 lines
Thanks,
NeilBrown
PATCH v2 1/1 nfs-server-generator: avoid using external services.
nfs-server-generator is run very early when a lot of services are not yet started, so it mustn't depend on them. Currently it can try to use hostname lookup and syslog. Using hostname lookup can cause errors and when these are logged via syslog, it can cause the generator to block indefinitely
Hostname-lookup is not needed, as we don't use the host issue, and sending message to stderr is sufficient for the generator.
Disabling syslog is easy - call a function that sets a static variable.
Disabling hostname lookup requires adding an "ignore_hosts" flags to export_read and export_d_read().
---
Hi Steve,
I decided that you were right and the interface wasn't really very nice.
And it wasn't that hard to make a more sensible interface. So I did that. Less need for comments, but I put an appropriate comment in anyway.
Thanks,
NeilBrown
support/export/export.c | 13 +++++++++---- support/include/exportfs.h | 4 ++-- systemd/nfs-server-generator.c | 4 ++-- utils/exportfs/exportfs.c | 4 ++-- 4 files changed, 15 insertions(+), 10 deletions(-)
support/export/export.c +9 -4
@@ -70,11 +70,15 @@ static void warn_duplicated_exports(nfs_export *exp, struct exportent *eep)/** * export_read - read entries from /etc/exports * @fname: name of file to read from +* @ignore_hosts: don't check validity of host names * * Returns number of read entries. +* @ignore_hosts can be set when the host names won't be used +* and when getting delays or errors due to problems with +* hostname looking is not acceptable. */ int -export_read (char *fname) +export_read (char *fname,int ignore_hosts) {struct exportent *eep;nfs_export *exp;
@@ -83,7 +87,7 @@ export_read(char *fname)setexportent (fname,"r" );while ((eep =getexportent (0 ,1 )) !=NULL ) { - exp =export_lookup (eep->e_hostname, eep->e_path,0 ); + exp =export_lookup (eep->e_hostname, eep->e_path, ignore_hosts);if (!exp) {if (export_create (eep,0 ))/* possible complaints already logged */
@@ -100,13 +104,14 @@ export_read(char *fname)/** * export_d_read - read entries from /etc/exports. * @fname: name of directory to read from +* @ignore_hosts: don't check validity of host names * * Returns number of read entries. * Based on mnt_table_parse_dir() in * util-linux-ng/shlibs/mount/src/tab_parse.c */ int -export_d_read (const char *dname) +export_d_read (const char *dname,int ignore_hosts) {int n =0 , i;struct dirent **namelist =NULL ;
@@ -150,7 +155,7 @@ export_d_read(const char *dname)continue ; } - volumes +=export_read (fname); + volumes +=export_read (fname, ignore_hosts); }for (i =0 ; i < n; i++)
support/include/exportfs.h +2 -2
@@ -134,8 +134,8 @@ struct addrinfo * client_resolve(const struct sockaddr *sap);int client_member (const char *client,const char *name); -int export_read (char *fname); -int export_d_read (const char *dname); +int export_read (char *fname,int ignore_hosts); +int export_d_read (const char *dname,int ignore_hosts);void export_reset (nfs_export *);nfs_export *export_lookup (char *hname,char *path,int caconical); nfs_export * export_find(const struct addrinfo *ai,
systemd/nfs-server-generator.c +2 -2
@@ -102,8 +102,8 @@ int main(int argc, char *argv[]) path =malloc (strlen (argv[1 ]) +sizeof (dirbase) +sizeof (filebase));if (!path)exit (2 ); -if (export_read (_PATH_EXPORTS) + -export_d_read (_PATH_EXPORTS_D) ==0 ) +if (export_read (_PATH_EXPORTS,1 ) + +export_d_read (_PATH_EXPORTS_D,1 ) ==0 )/* Nothing is exported, so nothing to do */ exit (0 );
utils/exportfs/exportfs.c +2 -2
@@ -183,8 +183,8 @@ main(int argc, char **argv)atexit (release_lockfile);if (f_export && ! f_ignore) { -if (! (export_read (_PATH_EXPORTS) + -export_d_read (_PATH_EXPORTS_D))) { +if (! (export_read (_PATH_EXPORTS,0 ) + +export_d_read (_PATH_EXPORTS_D,0 ))) {if (f_verbose)xlog (L_WARNING ,"No file systems exported!" ); }
Signature · 1 line
2.10.1
Quoted 9 lines · NeilBrown
nfs-server-generator is run very early when a lot of services are not yet started, so it mustn't depend on them. Currently it can try to use hostname lookup and syslog. Using hostname lookup can cause errors and when these are logged via syslog, it can cause the generator to block indefinitely
Hostname-lookup is not needed, as we don't use the host issue, and sending message to stderr is sufficient for the generator.
Quoted 6 lines
Disabling syslog is easy - call a function that sets a static variable.
Disabling hostname lookup requires adding an "
ignore_hosts" flags toexport_readandexport_d_read().Signed-off-by NeilBrown <[email protected]>
Committed!
steved.
Quoted 119 lines
---
Hi Steve,
I decided that you were right and the interface wasn't really very nice.
And it wasn't that hard to make a more sensible interface. So I did that. Less need for comments, but I put an appropriate comment in anyway.Thanks,
NeilBrownsupport/export/export.c | 13 +++++++++---- support/include/exportfs.h | 4 ++-- systemd/nfs-server-generator.c | 4 ++-- utils/exportfs/exportfs.c | 4 ++-- 4 files changed, 15 insertions(+), 10 deletions(-)support/export/export.c +9
-4@@ -70,11 +70,15 @@ static void warn_duplicated_exports(nfs_export *exp, struct exportent *eep)/** * export_read - read entries from /etc/exports * @fname: name of file to read from +* @ignore_hosts: don't check validity of host names * * Returns number of read entries. +* @ignore_hosts can be set when the host names won't be used +* and when getting delays or errors due to problems with +* hostname looking is not acceptable. */ int -export_read (char *fname) +export_read (char *fname,int ignore_hosts) {struct exportent *eep;nfs_export *exp;@@ -83,7 +87,7 @@ export_read(char *fname)setexportent (fname,"r" );while ((eep =getexportent (0 ,1 )) !=NULL ) { - exp =export_lookup (eep->e_hostname, eep->e_path,0 ); + exp =export_lookup (eep->e_hostname, eep->e_path, ignore_hosts);if (!exp) {if (export_create (eep,0 ))/* possible complaints already logged */ @@ -100,13 +104,14 @@ export_read(char *fname)/** * export_d_read - read entries from /etc/exports. * @fname: name of directory to read from +* @ignore_hosts: don't check validity of host names * * Returns number of read entries. * Based on mnt_table_parse_dir() in * util-linux-ng/shlibs/mount/src/tab_parse.c */ int -export_d_read (const char *dname) +export_d_read (const char *dname,int ignore_hosts) {int n =0 , i;struct dirent **namelist =NULL ;@@ -150,7 +155,7 @@ export_d_read(const char *dname)continue ; } - volumes +=export_read (fname); + volumes +=export_read (fname, ignore_hosts); }for (i =0 ; i < n; i++)support/include/exportfs.h +2
-2@@ -134,8 +134,8 @@ struct addrinfo * client_resolve(const struct sockaddr *sap);int client_member (const char *client,const char *name); -int export_read (char *fname); -int export_d_read (const char *dname); +int export_read (char *fname,int ignore_hosts); +int export_d_read (const char *dname,int ignore_hosts);void export_reset (nfs_export *);nfs_export *export_lookup (char *hname,char *path,int caconical); nfs_export * export_find(const struct addrinfo *ai,systemd/nfs-server-generator.c +2
-2@@ -102,8 +102,8 @@ int main(int argc, char *argv[]) path =malloc (strlen (argv[1 ]) +sizeof (dirbase) +sizeof (filebase));if (!path)exit (2 ); -if (export_read (_PATH_EXPORTS) + -export_d_read (_PATH_EXPORTS_D) ==0 ) +if (export_read (_PATH_EXPORTS,1 ) + +export_d_read (_PATH_EXPORTS_D,1 ) ==0 )/* Nothing is exported, so nothing to do */ exit (0 );utils/exportfs/exportfs.c +2
-2@@ -183,8 +183,8 @@ main(int argc, char **argv)atexit (release_lockfile);if (f_export && ! f_ignore) { -if (! (export_read (_PATH_EXPORTS) + -export_d_read (_PATH_EXPORTS_D))) { +if (! (export_read (_PATH_EXPORTS,0 ) + +export_d_read (_PATH_EXPORTS_D,0 ))) {if (f_verbose)xlog (L_WARNING ,"No file systems exported!" ); }