Whamcloud - gitweb
LU-10092 pcc: Non-blocking PCC caching
[fs/lustre-release.git] / lustre / utils / lfs.c
index 02bad77..d11c61c 100644 (file)
@@ -128,6 +128,7 @@ static inline int lfs_mirror_read(int argc, char **argv);
 static inline int lfs_mirror_write(int argc, char **argv);
 static inline int lfs_mirror_copy(int argc, char **argv);
 static int lfs_pcc_attach(int argc, char **argv);
+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);
@@ -339,6 +340,12 @@ command_t pcc_cmdlist[] = {
          .pc_help = "Attach given files to the Persistent Client Cache.\n"
                "usage: lfs pcc attach <--id|-i NUM> <file> ...\n"
                "\t-i: archive id for RW-PCC\n" },
+       { .pc_name = "attach_fid", .pc_func = lfs_pcc_attach_fid,
+         .pc_help = "Attach given files into PCC by FID(s).\n"
+               "usage: lfs pcc attach_id <--id|-i NUM> <--mnt|-m mnt> "
+               "<fid> ...\n"
+               "\t-i: archive id for RW-PCC\n"
+               "\t-m: Lustre mount point\n" },
        { .pc_name = "state", .pc_func = lfs_pcc_state,
          .pc_help = "Display the PCC state for given files.\n"
                "usage: lfs pcc state <file> ...\n" },
@@ -664,6 +671,7 @@ command_t cmdlist[] = {
        {"pcc", lfs_pcc, pcc_cmdlist,
         "lfs commands used to interact with PCC features:\n"
         "lfs pcc attach - attach given files to Persistent Client Cache\n"
+        "lfs pcc attach_fid - attach given files into PCC by FID(s)\n"
         "lfs pcc state  - display the PCC state for given files\n"
         "lfs pcc detach - detach given files from Persistent Client Cache\n"
         "lfs pcc detach_fid - detach given files from PCC by FID(s)\n"},
@@ -10433,6 +10441,79 @@ static int lfs_pcc_attach(int argc, char **argv)
        return rc;
 }
 
+static int lfs_pcc_attach_fid(int argc, char **argv)
+{
+       struct option long_opts[] = {
+       { .val = 'i',   .name = "id",   .has_arg = required_argument },
+       { .val = 'm',   .name = "mnt",  .has_arg = required_argument },
+       { .name = NULL } };
+       char                     short_opts[] = "i:m:";
+       int                      c;
+       int                      rc = 0;
+       __u32                    archive_id = 0;
+       char                    *end;
+       const char              *mntpath = NULL;
+       const char              *fidstr;
+       enum lu_pcc_type         type = LU_PCC_READWRITE;
+
+       optind = 0;
+       while ((c = getopt_long(argc, argv, short_opts,
+                               long_opts, NULL)) != -1) {
+               switch (c) {
+               case 'i':
+                       archive_id = strtoul(optarg, &end, 0);
+                       if (*end != '\0') {
+                               fprintf(stderr, "error: %s: bad archive ID "
+                                       "'%s'\n", argv[0], optarg);
+                               return CMD_HELP;
+                       }
+                       break;
+               case 'm':
+                       mntpath = optarg;
+                       break;
+               case '?':
+                       return CMD_HELP;
+               default:
+                       fprintf(stderr, "%s: option '%s' unrecognized\n",
+                               argv[0], argv[optind - 1]);
+                       return CMD_HELP;
+               }
+       }
+
+       if (archive_id == 0) {
+               fprintf(stderr, "%s: must specify an archive ID\n", argv[0]);
+               return CMD_HELP;
+       }
+
+       if (mntpath == NULL) {
+               fprintf(stderr, "%s: must specify Lustre mount point\n",
+                       argv[0]);
+               return CMD_HELP;
+       }
+
+       if (argc <= optind) {
+               fprintf(stderr, "%s: must specify one or more fids\n", argv[0]);
+               return CMD_HELP;
+       }
+
+       while (optind < argc) {
+               int rc2;
+
+               fidstr = argv[optind++];
+
+               rc2 = llapi_pcc_attach_fid_str(mntpath, fidstr,
+                                              archive_id, type);
+               if (rc2 < 0) {
+                       fprintf(stderr, "%s: cannot attach '%s' on '%s' to PCC "
+                               "with archive ID '%u': %s\n", argv[0],
+                               fidstr, mntpath, archive_id, strerror(rc2));
+               }
+               if (rc == 0 && rc2 < 0)
+                       rc = rc2;
+       }
+       return rc;
+}
+
 static int lfs_pcc_detach(int argc, char **argv)
 {
        int                      rc = 0;
@@ -10461,8 +10542,9 @@ static int lfs_pcc_detach(int argc, char **argv)
 
                rc2 = llapi_pcc_detach_file(fullpath);
                if (rc2 < 0) {
+                       rc2 = -errno;
                        fprintf(stderr, "%s: cannot detach '%s' from PCC: "
-                               "%s\n", argv[0], path, strerror(-rc2));
+                               "%s\n", argv[0], path, strerror(errno));
                        if (rc == 0)
                                rc = rc2;
                }
@@ -10549,9 +10631,7 @@ static int lfs_pcc_state(int argc, char **argv)
 
                printf(", PCC file: %s", state.pccs_path);
                printf(", user number: %u", state.pccs_open_count);
-               printf(", attr cached: %s",
-                      state.pccs_flags &  PCC_STATE_FLAG_ATTR_VALID ?
-                      "true" : "false");
+               printf(", flags: %x", state.pccs_flags);
                printf("\n");
        }
        return rc;