+ if (arg_template) {
+ r = btrfs_subvol_snapshot(arg_template, arg_directory, arg_read_only, true);
+ if (r == -EEXIST) {
+ if (!arg_quiet)
+ log_info("Directory %s already exists, not populating from template %s.", arg_directory, arg_template);
+ } else if (r < 0) {
+ log_error_errno(r, "Couldn't create snapshort %s from %s: %m", arg_directory, arg_template);
+ goto finish;
+ } else {
+ if (!arg_quiet)
+ log_info("Populated %s from template %s.", arg_directory, arg_template);
+ }
+
+ } else if (arg_ephemeral) {
+ char *np;
+
+ /* If the specified path is a mount point we
+ * generate the new snapshot immediately
+ * inside it under a random name. However if
+ * the specified is not a mount point we
+ * create the new snapshot in the parent
+ * directory, just next to it. */
+ r = path_is_mount_point(arg_directory, false);
+ if (r < 0) {
+ log_error_errno(r, "Failed to determine whether directory %s is mount point: %m", arg_directory);
+ goto finish;
+ }
+ if (r > 0)
+ r = tempfn_random_child(arg_directory, &np);
+ else
+ r = tempfn_random(arg_directory, &np);
+ if (r < 0) {
+ log_error_errno(r, "Failed to generate name for snapshot: %m");
+ goto finish;
+ }
+
+ r = btrfs_subvol_snapshot(arg_directory, np, arg_read_only, true);
+ if (r < 0) {
+ free(np);
+ log_error_errno(r, "Failed to create snapshot %s from %s: %m", np, arg_directory);
+ goto finish;
+ }
+
+ free(arg_directory);
+ arg_directory = np;
+
+ remove_subvol = true;
+ }
+