Does blockd intentionally skip mounts if device name exists in / ?

David Adair djabhead at aol.com
Mon Jun 7 19:53:18 PDT 2021


Since no one answered, I suggest that the original intent was to follow
the logic from the kernel.org autofs daemon sample aka automount.  The
existing code is very close but lacks a couple bits.

Neither of my suggestions accomplished this intent so I will provide a patch
that does shortly but did not want to clutter it up with gory detail.

In indirect.c ( blockd uses indirect maps so this is the best comparision )
we have (with pthread stuff removed)

	len = ncat_path(buf, sizeof(buf), ap->path, mt.name, mt.len);
	if (!len) {
	< not interesting error goop >
	}

	status = lstat(buf, &st);
	if (status != -1 && !(S_ISDIR(st.st_mode) && st.st_dev == mt.dev)) {
		error(ap->logopt,
		      "indirect trigger not valid or already mounted %s", buf);
		ops->send_ready(ap->logopt, ap->ioctlfd, mt.wait_queue_token);

	}

	info(ap->logopt, "attempting to mount entry %s", buf);

	set_tsd_user_vars(ap->logopt, mt.uid, mt.gid);
	status = lookup_nss_mount(ap, NULL, mt.name, mt.len);
	if (status) {
		ops->send_ready(ap->logopt,
				ap->ioctlfd, mt.wait_queue_token);

		info(ap->logopt, "mounted %s", buf);
	} else {
		/* TODO: get mount return status from lookup_nss_mount */
		ops->send_fail(ap->logopt,
			       ap->ioctlfd, mt.wait_queue_token, -ENOENT);
		info(ap->logopt, "failed to mount %s", buf);
	}


For blockd the existence of the soft-link in /mnt is equivalent to the
lookup request with nss/cache operation so this would translate to:

 - if dir exists in /tmp/run/blockd and IS NOT a leftover zombie with
   device == /tmp/run/blockd device. Then do nothing and report success.

 - remove dir if it exists.

 - if link is present in /mnt and block mount succeeds report success.

 - otherwise report failure.

Recent autofs v5 docs (filesystems/autofs.rst) make a big deal about errors
caused by pgid != automount messing with the mount points.
	Too many levels of symbolic links
My assuption is that the second part of the test which fixes these
"poison" directories:
!(S_ISDIR(st.st_mode) && st.st_dev == mt.dev)
was not included because it did not exist when the code was written.

As far as the missing "ncat_path" my guess is that was either overlooked
or some earlier kernel abi provided the full path.

Using the logic from automount is working much nicer:
  - No more "suprise" illegal volume names.
  - Hotplug-out actually stops mount requests when link is removed instead
    of having mount re-appear just as we are trying to lvchange -an.
  - System gracefully and automatically recovers from user-initiated umounts.







More information about the openwrt-devel mailing list