From ae0b392f90fc7e47836d49997300abd998b653c4 Mon Sep 17 00:00:00 2001 From: Chris Vittal Date: Sun, 24 May 2020 19:20:16 -0400 Subject: [PATCH] Get more subvolume paths. --- snapmgr.c | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/snapmgr.c b/snapmgr.c index 179189f..51663c2 100644 --- a/snapmgr.c +++ b/snapmgr.c @@ -43,6 +43,15 @@ take(const char *vol, const char *path) strftime(name, sizeof(name), "%Y%m%dT%H%M%S%z", tm); enum btrfs_util_error err; + char *subvol_path = NULL; + + err = btrfs_util_subvolume_path_fd(vfd, 0, &subvol_path); + if (err) { + syslog(LOG_WARNING, "could not get subvolume path of '%s': %s", + vol, btrfs_util_strerror(err)); + subvol_path = strdup(vol); + } + err = btrfs_util_create_snapshot_fd2(vfd, dfd, name, 0, NULL, NULL); int ret; if (err) { @@ -51,7 +60,7 @@ take(const char *vol, const char *path) ret = 1; } else { syslog(LOG_INFO, "created snapshot of %s at %s/%s\n", - vol, path, name); + subvol_path, path, name); ret = 0; } @@ -91,7 +100,7 @@ maybe_prune_subvolume(int dfd, char *fullpath, struct dirent *dirent, if (err) { syslog(LOG_WARNING, "cannot get subvol path: %s", btrfs_util_strerror(err)); - path = fullpath; + path = strdup(fullpath); } err = btrfs_util_delete_subvolume_fd(dfd, dirent->d_name, 0); @@ -106,9 +115,7 @@ maybe_prune_subvolume(int dfd, char *fullpath, struct dirent *dirent, ret = 0; } - if (path != fullpath) { - free(path); - } + free(path); return ret; } @@ -132,7 +139,7 @@ prune(const char *vol, const char *path) enum btrfs_util_error err; struct btrfs_util_subvolume_info subvol; - char *subvol_path = fullpath; + char *subvol_path = NULL; err = btrfs_util_subvolume_info_fd(vfd, 0, &subvol); if (err) { @@ -144,7 +151,7 @@ prune(const char *vol, const char *path) if (err) { syslog(LOG_WARNING, "prune: can't get subvolume path: %s", btrfs_util_strerror(err)); - subvol_path = fullpath; + subvol_path = strdup(fullpath); } DIR *dir = opendir(fullpath); @@ -164,16 +171,12 @@ prune(const char *vol, const char *path) closedir(dir); close(vfd); - if (fullpath != subvol_path) { - free(subvol_path); - } + free(subvol_path); free(fullpath); return ret; prune_err: close(vfd); - if (fullpath != subvol_path) { - free(subvol_path); - } + free(subvol_path); free(fullpath); return 1; } -- 2.45.2