|
|
9a499a |
autofs-5.1.7 - refactor umount_multi_triggers()
|
|
|
9a499a |
|
|
|
9a499a |
From: Ian Kent <raven@themaw.net>
|
|
|
9a499a |
|
|
|
9a499a |
Refactor umount_multi_triggers() to try the umount of an offset subtree
|
|
|
9a499a |
in a seperate function.
|
|
|
9a499a |
|
|
|
9a499a |
Signed-off-by: Ian Kent <raven@themaw.net>
|
|
|
9a499a |
---
|
|
|
9a499a |
CHANGELOG | 1
|
|
|
9a499a |
lib/mounts.c | 187 ++++++++++++++++++++++++++++++++---------------------------
|
|
|
9a499a |
2 files changed, 104 insertions(+), 84 deletions(-)
|
|
|
9a499a |
|
|
|
9a499a |
--- autofs-5.1.4.orig/CHANGELOG
|
|
|
9a499a |
+++ autofs-5.1.4/CHANGELOG
|
|
|
9a499a |
@@ -10,6 +10,7 @@
|
|
|
9a499a |
- set offset parent in update_offset_entry().
|
|
|
9a499a |
- remove redundant variables from mount_autofs_offset().
|
|
|
9a499a |
- remove unused parameter form do_mount_autofs_offset().
|
|
|
9a499a |
+- refactor umount_multi_triggers().
|
|
|
9a499a |
|
|
|
9a499a |
xx/xx/2018 autofs-5.1.5
|
|
|
9a499a |
- fix flag file permission.
|
|
|
9a499a |
--- autofs-5.1.4.orig/lib/mounts.c
|
|
|
9a499a |
+++ autofs-5.1.4/lib/mounts.c
|
|
|
9a499a |
@@ -2490,57 +2490,6 @@ static int do_mount_autofs_offset(struct
|
|
|
9a499a |
return mounted;
|
|
|
9a499a |
}
|
|
|
9a499a |
|
|
|
9a499a |
-int mount_multi_triggers(struct autofs_point *ap, struct mapent *me,
|
|
|
9a499a |
- const char *root, unsigned int start, const char *base)
|
|
|
9a499a |
-{
|
|
|
9a499a |
- char path[PATH_MAX + 1];
|
|
|
9a499a |
- char *offset = path;
|
|
|
9a499a |
- struct mapent *oe;
|
|
|
9a499a |
- struct list_head *pos = NULL;
|
|
|
9a499a |
- unsigned int root_len = strlen(root);
|
|
|
9a499a |
- int mounted;
|
|
|
9a499a |
-
|
|
|
9a499a |
- mounted = 0;
|
|
|
9a499a |
- offset = cache_get_offset(base, offset, start, &me->multi_list, &pos;;
|
|
|
9a499a |
- while (offset) {
|
|
|
9a499a |
- char key[PATH_MAX + 1];
|
|
|
9a499a |
- int key_len = root_len + strlen(offset);
|
|
|
9a499a |
-
|
|
|
9a499a |
- if (key_len > PATH_MAX) {
|
|
|
9a499a |
- warn(ap->logopt, "path loo long");
|
|
|
9a499a |
- goto cont;
|
|
|
9a499a |
- }
|
|
|
9a499a |
-
|
|
|
9a499a |
- /* The root offset is always mounted seperately so the
|
|
|
9a499a |
- * offset path will always be root + offset.
|
|
|
9a499a |
- */
|
|
|
9a499a |
- strcpy(key, root);
|
|
|
9a499a |
- strcat(key, offset);
|
|
|
9a499a |
-
|
|
|
9a499a |
- oe = cache_lookup_distinct(me->mc, key);
|
|
|
9a499a |
- if (!oe || !oe->mapent)
|
|
|
9a499a |
- goto cont;
|
|
|
9a499a |
-
|
|
|
9a499a |
- mounted += do_mount_autofs_offset(ap, oe, root);
|
|
|
9a499a |
-
|
|
|
9a499a |
- /*
|
|
|
9a499a |
- * If re-constructing a multi-mount it's necessary to walk
|
|
|
9a499a |
- * into nested mounts, unlike the usual "mount only what's
|
|
|
9a499a |
- * needed as you go" behavior.
|
|
|
9a499a |
- */
|
|
|
9a499a |
- if (ap->state == ST_READMAP && ap->flags & MOUNT_FLAG_REMOUNT) {
|
|
|
9a499a |
- if (oe->ioctlfd != -1 ||
|
|
|
9a499a |
- is_mounted(oe->key, MNTS_REAL))
|
|
|
9a499a |
- mount_multi_triggers(ap, oe, key, strlen(key), base);
|
|
|
9a499a |
- }
|
|
|
9a499a |
-cont:
|
|
|
9a499a |
- offset = cache_get_offset(base,
|
|
|
9a499a |
- offset, start, &me->multi_list, &pos;;
|
|
|
9a499a |
- }
|
|
|
9a499a |
-
|
|
|
9a499a |
- return mounted;
|
|
|
9a499a |
-}
|
|
|
9a499a |
-
|
|
|
9a499a |
static int rmdir_path_offset(struct autofs_point *ap, struct mapent *oe)
|
|
|
9a499a |
{
|
|
|
9a499a |
char *dir, *path;
|
|
|
9a499a |
@@ -2576,7 +2525,10 @@ static int rmdir_path_offset(struct auto
|
|
|
9a499a |
return ret;
|
|
|
9a499a |
}
|
|
|
9a499a |
|
|
|
9a499a |
-int umount_multi_triggers(struct autofs_point *ap, struct mapent *me, char *root, const char *base)
|
|
|
9a499a |
+static int do_umount_offset(struct autofs_point *ap, struct mapent *oe, const char *root);
|
|
|
9a499a |
+
|
|
|
9a499a |
+static int do_umount_multi_triggers(struct autofs_point *ap,
|
|
|
9a499a |
+ struct mapent *me, const char *root, const char *base)
|
|
|
9a499a |
{
|
|
|
9a499a |
char path[PATH_MAX + 1];
|
|
|
9a499a |
char *offset;
|
|
|
9a499a |
@@ -2606,7 +2558,6 @@ int umount_multi_triggers(struct autofs_
|
|
|
9a499a |
while ((offset = cache_get_offset(mm_base, offset, start, mm_root, &pos))) {
|
|
|
9a499a |
char key[PATH_MAX + 1];
|
|
|
9a499a |
int key_len = root_len + strlen(offset);
|
|
|
9a499a |
- char *oe_base;
|
|
|
9a499a |
|
|
|
9a499a |
if (mm_base_len > 1)
|
|
|
9a499a |
key_len += mm_base_len;
|
|
|
9a499a |
@@ -2626,47 +2577,116 @@ int umount_multi_triggers(struct autofs_
|
|
|
9a499a |
if (!oe || (strlen(oe->key) - start) == 1)
|
|
|
9a499a |
continue;
|
|
|
9a499a |
|
|
|
9a499a |
+ left += do_umount_offset(ap, oe, root);
|
|
|
9a499a |
+ }
|
|
|
9a499a |
+
|
|
|
9a499a |
+ return left;
|
|
|
9a499a |
+}
|
|
|
9a499a |
+
|
|
|
9a499a |
+static int do_umount_offset(struct autofs_point *ap, struct mapent *oe, const char *root)
|
|
|
9a499a |
+{
|
|
|
9a499a |
+ char *oe_base;
|
|
|
9a499a |
+ int left = 0;
|
|
|
9a499a |
+
|
|
|
9a499a |
+ /*
|
|
|
9a499a |
+ * Check for and umount subtree offsets resulting from
|
|
|
9a499a |
+ * nonstrict mount fail.
|
|
|
9a499a |
+ */
|
|
|
9a499a |
+ oe_base = oe->key + strlen(root);
|
|
|
9a499a |
+ left += do_umount_multi_triggers(ap, oe, root, oe_base);
|
|
|
9a499a |
+
|
|
|
9a499a |
+ if (oe->ioctlfd != -1 ||
|
|
|
9a499a |
+ is_mounted(oe->key, MNTS_REAL)) {
|
|
|
9a499a |
+ left++;
|
|
|
9a499a |
+ return left;
|
|
|
9a499a |
+ }
|
|
|
9a499a |
+
|
|
|
9a499a |
+ debug(ap->logopt, "umount offset %s", oe->key);
|
|
|
9a499a |
+
|
|
|
9a499a |
+ if (umount_autofs_offset(ap, oe)) {
|
|
|
9a499a |
+ warn(ap->logopt, "failed to umount offset");
|
|
|
9a499a |
+ left++;
|
|
|
9a499a |
+ } else {
|
|
|
9a499a |
+ struct stat st;
|
|
|
9a499a |
+ int ret;
|
|
|
9a499a |
+
|
|
|
9a499a |
+ if (!(oe->flags & MOUNT_FLAG_DIR_CREATED))
|
|
|
9a499a |
+ return left;
|
|
|
9a499a |
+
|
|
|
9a499a |
/*
|
|
|
9a499a |
- * Check for and umount subtree offsets resulting from
|
|
|
9a499a |
- * nonstrict mount fail.
|
|
|
9a499a |
+ * An error due to partial directory removal is
|
|
|
9a499a |
+ * ok so only try and remount the offset if the
|
|
|
9a499a |
+ * actual mount point still exists.
|
|
|
9a499a |
*/
|
|
|
9a499a |
- oe_base = oe->key + strlen(root);
|
|
|
9a499a |
- left += umount_multi_triggers(ap, oe, root, oe_base);
|
|
|
9a499a |
+ ret = rmdir_path_offset(ap, oe);
|
|
|
9a499a |
+ if (ret == -1 && !stat(oe->key, &st)) {
|
|
|
9a499a |
+ ret = do_mount_autofs_offset(ap, oe, root);
|
|
|
9a499a |
+ if (ret)
|
|
|
9a499a |
+ left++;
|
|
|
9a499a |
+ /* But we did origianlly create this */
|
|
|
9a499a |
+ oe->flags |= MOUNT_FLAG_DIR_CREATED;
|
|
|
9a499a |
+ }
|
|
|
9a499a |
+ }
|
|
|
9a499a |
+ return left;
|
|
|
9a499a |
+}
|
|
|
9a499a |
|
|
|
9a499a |
- if (oe->ioctlfd != -1 ||
|
|
|
9a499a |
- is_mounted(oe->key, MNTS_REAL)) {
|
|
|
9a499a |
- left++;
|
|
|
9a499a |
- continue;
|
|
|
9a499a |
+int mount_multi_triggers(struct autofs_point *ap, struct mapent *me,
|
|
|
9a499a |
+ const char *root, unsigned int start, const char *base)
|
|
|
9a499a |
+{
|
|
|
9a499a |
+ char path[PATH_MAX + 1];
|
|
|
9a499a |
+ char *offset = path;
|
|
|
9a499a |
+ struct mapent *oe;
|
|
|
9a499a |
+ struct list_head *pos = NULL;
|
|
|
9a499a |
+ unsigned int root_len = strlen(root);
|
|
|
9a499a |
+ int mounted;
|
|
|
9a499a |
+
|
|
|
9a499a |
+ mounted = 0;
|
|
|
9a499a |
+ offset = cache_get_offset(base, offset, start, &me->multi_list, &pos;;
|
|
|
9a499a |
+ while (offset) {
|
|
|
9a499a |
+ char key[PATH_MAX + 1];
|
|
|
9a499a |
+ int key_len = root_len + strlen(offset);
|
|
|
9a499a |
+
|
|
|
9a499a |
+ if (key_len > PATH_MAX) {
|
|
|
9a499a |
+ warn(ap->logopt, "path loo long");
|
|
|
9a499a |
+ goto cont;
|
|
|
9a499a |
}
|
|
|
9a499a |
|
|
|
9a499a |
- debug(ap->logopt, "umount offset %s", oe->key);
|
|
|
9a499a |
+ /* The root offset is always mounted seperately so the
|
|
|
9a499a |
+ * offset path will always be root + offset.
|
|
|
9a499a |
+ */
|
|
|
9a499a |
+ strcpy(key, root);
|
|
|
9a499a |
+ strcat(key, offset);
|
|
|
9a499a |
|
|
|
9a499a |
- if (umount_autofs_offset(ap, oe)) {
|
|
|
9a499a |
- warn(ap->logopt, "failed to umount offset");
|
|
|
9a499a |
- left++;
|
|
|
9a499a |
- } else {
|
|
|
9a499a |
- struct stat st;
|
|
|
9a499a |
- int ret;
|
|
|
9a499a |
+ oe = cache_lookup_distinct(me->mc, key);
|
|
|
9a499a |
+ if (!oe || !oe->mapent)
|
|
|
9a499a |
+ goto cont;
|
|
|
9a499a |
|
|
|
9a499a |
- if (!(oe->flags & MOUNT_FLAG_DIR_CREATED))
|
|
|
9a499a |
- continue;
|
|
|
9a499a |
+ mounted += do_mount_autofs_offset(ap, oe, root);
|
|
|
9a499a |
|
|
|
9a499a |
- /*
|
|
|
9a499a |
- * An error due to partial directory removal is
|
|
|
9a499a |
- * ok so only try and remount the offset if the
|
|
|
9a499a |
- * actual mount point still exists.
|
|
|
9a499a |
- */
|
|
|
9a499a |
- ret = rmdir_path_offset(ap, oe);
|
|
|
9a499a |
- if (ret == -1 && !stat(oe->key, &st)) {
|
|
|
9a499a |
- ret = do_mount_autofs_offset(ap, oe, root);
|
|
|
9a499a |
- if (ret)
|
|
|
9a499a |
- left++;
|
|
|
9a499a |
- /* But we did origianlly create this */
|
|
|
9a499a |
- oe->flags |= MOUNT_FLAG_DIR_CREATED;
|
|
|
9a499a |
- }
|
|
|
9a499a |
+ /*
|
|
|
9a499a |
+ * If re-constructing a multi-mount it's necessary to walk
|
|
|
9a499a |
+ * into nested mounts, unlike the usual "mount only what's
|
|
|
9a499a |
+ * needed as you go" behavior.
|
|
|
9a499a |
+ */
|
|
|
9a499a |
+ if (ap->state == ST_READMAP && ap->flags & MOUNT_FLAG_REMOUNT) {
|
|
|
9a499a |
+ if (oe->ioctlfd != -1 ||
|
|
|
9a499a |
+ is_mounted(oe->key, MNTS_REAL))
|
|
|
9a499a |
+ mount_multi_triggers(ap, oe, key, strlen(key), base);
|
|
|
9a499a |
}
|
|
|
9a499a |
+cont:
|
|
|
9a499a |
+ offset = cache_get_offset(base,
|
|
|
9a499a |
+ offset, start, &me->multi_list, &pos;;
|
|
|
9a499a |
}
|
|
|
9a499a |
|
|
|
9a499a |
+ return mounted;
|
|
|
9a499a |
+}
|
|
|
9a499a |
+
|
|
|
9a499a |
+int umount_multi_triggers(struct autofs_point *ap, struct mapent *me, char *root, const char *base)
|
|
|
9a499a |
+{
|
|
|
9a499a |
+ int left;
|
|
|
9a499a |
+
|
|
|
9a499a |
+ left = do_umount_multi_triggers(ap, me, root, base);
|
|
|
9a499a |
+
|
|
|
9a499a |
if (!left && me->multi == me) {
|
|
|
9a499a |
struct mapent_cache *mc = me->mc;
|
|
|
9a499a |
int status;
|
|
|
9a499a |
@@ -2865,4 +2885,3 @@ int clean_stale_multi_triggers(struct au
|
|
|
9a499a |
|
|
|
9a499a |
return left;
|
|
|
9a499a |
}
|
|
|
9a499a |
-
|