From 01b82baffed95d64fd564229c829543a0e57bf31 Mon Sep 17 00:00:00 2001 From: Qian Yingjin Date: Wed, 20 Oct 2021 12:07:14 +0800 Subject: [PATCH] LU-10499 pcc: command to remove PCC mirror component This patch adds a command "lfs pcc delete $FILE" to delete the PCC foreign mirror layout component. Describe fields in lfs-pcc-state.1 and lfs-pcc-delete.1 page. EX-bug-id: EX-4055 Signed-off-by: Qian Yingjin Signed-off-by: Andreas Dilger Change-Id: I3f56fb8134bd1e7673ef8e04dff9b8482f0e32c3 Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/54457 Tested-by: jenkins Tested-by: Maloo Reviewed-by: James Simmons Reviewed-by: Oleg Drokin --- lustre/utils/lfs.c | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 71 insertions(+), 4 deletions(-) diff --git a/lustre/utils/lfs.c b/lustre/utils/lfs.c index 054ad65..786062d 100755 --- a/lustre/utils/lfs.c +++ b/lustre/utils/lfs.c @@ -147,6 +147,7 @@ static int lfs_pcc_attach_fid(int argc, char **argv); static int lfs_pcc_detach(int argc, char **argv); static int lfs_pcc_detach_fid(int argc, char **argv); static int lfs_pcc_state(int argc, char **argv); +static int lfs_pcc_delete(int argc, char **argv); static int lfs_pcc(int argc, char **argv); static int lfs_migrate_to_dom(int fd_src, int fd_dst, char *name, @@ -348,6 +349,9 @@ command_t pcc_cmdlist[] = { { .pc_name = "detach_fid", .pc_func = lfs_pcc_detach_fid, .pc_help = "Detach given files from PCC by FID(s).\n" "usage: lfs pcc detach_fid {--mnt|-m MOUNTPATH} FID...\n" }, + { .pc_name = "delete", .pc_func = lfs_pcc_delete, + .pc_help = "Delete the PCC layout component for given files.\n" + "usage: lfs pcc delete ...\n" }, { .pc_help = NULL } }; @@ -1669,10 +1673,11 @@ struct mirror_args { * Flags for extending a mirrored file. */ enum mirror_flags { - MF_NO_VERIFY = 0x1, - MF_DESTROY = 0x2, - MF_COMP_ID = 0x4, - MF_COMP_POOL = 0x8, + MF_NO_VERIFY = 0x01, + MF_DESTROY = 0x02, + MF_COMP_ID = 0x04, + MF_COMP_POOL = 0x08, + MF_FOREIGN = 0x10, }; /** @@ -2188,6 +2193,28 @@ static int mirror_extend(char *fname, struct mirror_args *mirror_list, return rc; } +static int find_foreign_id(struct llapi_layout *layout, void *cbdata) +{ + uint64_t pattern; + uint32_t id; + int rc; + + rc = llapi_layout_pattern_get(layout, &pattern); + if (rc < 0) + return rc; + + if (pattern == LLAPI_LAYOUT_FOREIGN) { + rc = llapi_layout_mirror_id_get(layout, &id); + if (rc < 0) + return rc; + + *(uint32_t *)cbdata = id; + return LLAPI_LAYOUT_ITER_STOP; + } + + return LLAPI_LAYOUT_ITER_CONT; +} + static int find_mirror_id(struct llapi_layout *layout, void *cbdata) { uint32_t id; @@ -2388,6 +2415,9 @@ static int mirror_split(const char *fname, __u32 id, const char *pool, } else if (mflags & MF_COMP_ID) { rc = llapi_layout_comp_iterate(layout, find_comp_id, &id); mirror_id = mirror_id_of(id); + } else if (mflags & MF_FOREIGN) { + rc = llapi_layout_comp_iterate(layout, find_foreign_id, &id); + mirror_id = id; } else { rc = llapi_layout_comp_iterate(layout, find_mirror_id, &id); mirror_id = id; @@ -2407,6 +2437,11 @@ static int mirror_split(const char *fname, __u32 id, const char *pool, "error %s: file '%s' does not contain mirror with comp-id %u\n", progname, fname, id); goto free_layout; + } else if (mflags & MF_FOREIGN) { + fprintf(stderr, + "error %s: file '%s' does not contain foreign component\n", + progname, fname); + goto free_layout; } else { fprintf(stderr, "error %s: file '%s' does not contain mirror with id %u\n", @@ -14301,6 +14336,38 @@ static int lfs_pcc_state(int argc, char **argv) return rc; } +static int lfs_pcc_delete(int argc, char **argv) +{ + int rc = 0; + const char *path; + + optind = 1; + + if (argc <= 1) { + fprintf(stderr, "%s: must specify one or more file names\n", + argv[0]); + return CMD_HELP; + } + + while (optind < argc) { + int rc2; + + path = argv[optind++]; + rc2 = mirror_split(path, 0, NULL, + MF_DESTROY | MF_FOREIGN, NULL); + if (rc2 < 0) { + if (rc == 0) + rc = rc2; + fprintf(stderr, + "%s: failed to delete PCC for '%s': %s\n", + argv[0], path, strerror(-rc2)); + continue; + } + } + + return rc; +} + /** * lfs_pcc() - Parse and execute lfs pcc commands. * @argc: The count of lfs pcc command line arguments. -- 1.8.3.1