diff options
author | NeilBrown <neilb@suse.com> | 2017-02-15 10:33:49 -0500 |
---|---|---|
committer | Steve Dickson <steved@redhat.com> | 2017-02-15 10:41:59 -0500 |
commit | 40346e1503c3d52b43ed3fe2bf56742ac5454553 (patch) | |
tree | c15045becf429fc829aaceb077bf8b37f5d0c340 /systemd/nfs-server-generator.c | |
parent | 48cdcf68a9209ae239dfc3d1a0b482089ef2cd2a (diff) | |
download | nfs-utils-40346e1503c3d52b43ed3fe2bf56742ac5454553.tar.gz nfs-utils-40346e1503c3d52b43ed3fe2bf56742ac5454553.tar.xz nfs-utils-40346e1503c3d52b43ed3fe2bf56742ac5454553.zip |
nfs-server-generator: handle 'noauto' mounts correctly
When this code was written, the systemd documentation stated
that "RequiresMountsFor" ignored mountpoints marked as "noauto".
Unfortunately this is incorrect. Consquently a filesystem marked
as noauto that is also NFS exported will currently be mounted when
the NFS server is started. This is not what people expect.
So add a check for the noauto flag. If any ancestor of a given
export point has the noauto flag, no RequiresMountsFor will be
generated for that point.
Also skip RequiresMountsFor for exports marked 'mountpoint', as their
absence is, theoretically, already handled by mountd.
URL: https://github.com/systemd/systemd/issues/5249
Signed-off-by: NeilBrown <neilb@suse.com>
Signed-off-by: Steve Dickson <steved@redhat.com>
Diffstat (limited to 'systemd/nfs-server-generator.c')
-rw-r--r-- | systemd/nfs-server-generator.c | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/systemd/nfs-server-generator.c b/systemd/nfs-server-generator.c index cc99969..4aa6509 100644 --- a/systemd/nfs-server-generator.c +++ b/systemd/nfs-server-generator.c @@ -84,6 +84,28 @@ static void systemd_escape(FILE *f, char *path) } } +static int has_noauto_flag(char *path) +{ + FILE *fstab; + struct mntent *mnt; + + fstab = setmntent("/etc/fstab", "r"); + if (!fstab) + return 0; + + while ((mnt = getmntent(fstab)) != NULL) { + int l = strlen(mnt->mnt_dir); + if (strncmp(mnt->mnt_dir, path, l) != 0) + continue; + if (path[l] && path[l] != '/') + continue; + if (hasmntopt(mnt, "noauto")) + break; + } + fclose(fstab); + return mnt != NULL; +} + int main(int argc, char *argv[]) { char *path; @@ -124,6 +146,10 @@ int main(int argc, char *argv[]) for (exp = exportlist[i].p_head; exp; exp = exp->m_next) { if (!is_unique(&list, exp->m_export.e_path)) continue; + if (exp->m_export.e_mountpoint) + continue; + if (has_noauto_flag(exp->m_export.e_path)) + continue; if (strchr(exp->m_export.e_path, ' ')) fprintf(f, "RequiresMountsFor=\"%s\"\n", exp->m_export.e_path); |