lxc_unstack_mountpoint() tries to clear all mountpoints from a given path.
It return the number of successful umounts on success and -errno on error.
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
return fd_loop;
}
+
+int lxc_unstack_mountpoint(const char *path, bool lazy)
+{
+ int ret;
+ int umounts = 0;
+
+pop_stack:
+ ret = umount2(path, lazy ? MNT_DETACH : 0);
+ if (ret < 0) {
+ /* We consider anything else than EINVAL deadly to prevent going
+ * into an infinite loop. (The other alternative is constantly
+ * parsing /proc/self/mountinfo which is yucky and probably
+ * racy.)
+ */
+ if (errno != EINVAL)
+ return -errno;
+ } else {
+ /* We succeeded in umounting. Make sure that there's no other
+ * mountpoint stacked underneath.
+ */
+ umounts++;
+ goto pop_stack;
+ }
+
+ return umounts;
+}
/* Find an unused loop device and associate it with source. */
int lxc_prepare_loop_dev(const char *source, char *loop_dev, int flags);
+/* Clear all mounts on a given node.
+ * >= 0 successfully cleared. The number returned is the number of umounts
+ * performed.
+ * < 0 error umounting. Return -errno.
+ */
+int lxc_unstack_mountpoint(const char *path, bool lazy);
+
#endif /* __LXC_UTILS_H */