struct option long_opts[] = {
{ .val = 'k', .name = "keep", .has_arg = no_argument },
{ .name = NULL } };
- char short_opts[] = "k";
- int c;
- int rc = 0;
- const char *fid;
- const char *mntpath;
- __u32 detach_flags = PCC_DETACH_FL_UNCACHE;
+ char short_opts[] = "k";
+ int c;
+ int rc = 0;
+ const char *fidstr;
+ const char *mntpath;
+ __u32 detach_flags = PCC_DETACH_FL_UNCACHE;
+ int dirfd;
optind = 0;
while ((c = getopt_long(argc, argv, short_opts,
}
mntpath = argv[optind++];
+ dirfd = open(mntpath, O_RDONLY);
+ if (dirfd < 0) {
+ rc = -errno;
+ fprintf(stderr, "%s: cannot open '%s': %s",
+ argv[0], mntpath, strerror(errno));
+ return rc;
+ }
while (optind < argc) {
+ struct lu_fid fid;
int rc2;
- fid = argv[optind++];
+ fidstr = argv[optind++];
+ rc2 = llapi_fid_parse(fidstr, &fid, NULL);
+ if (rc2) {
+ fprintf(stderr, "%s: '%s' is not a valid FID\n",
+ argv[0], fidstr);
+ if (rc == 0)
+ rc = rc2;
+ continue;
+ }
- rc2 = llapi_pcc_detach_fid_str(mntpath, fid, detach_flags);
+ rc2 = llapi_pcc_detach_at(dirfd, &fid, detach_flags);
if (rc2 < 0) {
fprintf(stderr,
"%s: cannot detach '%s' on '%s' from PCC: %s\n",
- argv[0], fid, mntpath, strerror(-rc2));
+ argv[0], fidstr, mntpath, strerror(-rc2));
if (rc == 0)
rc = rc2;
}
}
+
+ close(dirfd);
return rc;
}
{
int rc;
struct lu_fid fid;
- const char *fidstr_orig = fidstr;
- while (*fidstr == '[')
- fidstr++;
- rc = sscanf(fidstr, SFID, RFID(&fid));
- if (rc != 3) {
+ rc = llapi_fid_parse(fidstr, &fid, NULL);
+ if (rc) {
llapi_err_noerrno(LLAPI_MSG_ERROR,
- "bad FID format '%s', should be [seq:oid:ver]"
- " (e.g. "DFID")\n", fidstr_orig,
- (unsigned long long)FID_SEQ_NORMAL, 2, 0);
+ "PCC: '%s' is not a valid FID", fidstr);
return -EINVAL;
}
/**
* detach PCC cache of a file via FID.
*
+ * \param dirfd Dir file handle.
+ * \param fid FID of the file.
+ * \param flags Detach flags.
+ *
+ * \return 0 on success, an error code otherwise.
+ */
+int llapi_pcc_detach_at(int dirfd, const struct lu_fid *fid,
+ enum lu_pcc_detach_flags flags)
+{
+ int rc;
+ struct lu_pcc_detach_fid detach = {
+ .pccd_fid = *fid,
+ .pccd_flags = flags,
+ };
+
+ rc = ioctl(dirfd, LL_IOC_PCC_DETACH_BY_FID, &detach);
+ return rc;
+}
+
+/**
+ * detach PCC cache of a file via FID.
+ *
* \param mntpath Fullpath to the client mount point.
* \param fid FID of the file.
* \param flags Detach flags.
{
int rc;
struct lu_fid fid;
- const char *fidstr_orig = fidstr;
- while (*fidstr == '[')
- fidstr++;
- rc = sscanf(fidstr, SFID, RFID(&fid));
- if (rc != 3 || !fid_is_sane(&fid)) {
+ rc = llapi_fid_parse(fidstr, &fid, NULL);
+ if (rc) {
llapi_err_noerrno(LLAPI_MSG_ERROR,
- "bad FID format '%s', should be [seq:oid:ver]"
- " (e.g. "DFID")\n", fidstr_orig,
- (unsigned long long)FID_SEQ_NORMAL, 2, 0);
+ "PCC: '%s' is not a valid FID", fidstr);
return -EINVAL;
}
char fidstr[FID_LEN];
const char *fidname;
bool lov_file;
- int fd;
int rc;
/* It is the saved lov file when archive on HSM backend. */
fidname = fname;
}
- rc = sscanf(fidname, SFID, RFID(&detach.pccd_fid));
- if (rc != 3 || !fid_is_sane(&detach.pccd_fid)) {
- llapi_err_noerrno(LLAPI_MSG_ERROR,
- "bad FID format '%s', should be [seq:oid:ver] (e.g. "DFID")\n",
- fidname, (unsigned long long)FID_SEQ_NORMAL,
- 2, 0);
- return -EINVAL;
- }
-
- llapi_printf(LLAPI_MSG_DEBUG, "Handle the file: %s\n", fidname);
-
- rc = get_root_path(WANT_FD, NULL, &fd, (char *)hsc->hsc_mntpath, -1);
+ rc = llapi_fid_parse(fidname, &detach.pccd_fid, NULL);
if (rc) {
- llapi_error(LLAPI_MSG_ERROR, rc, "cannot get root path: %s",
- hsc->hsc_mntpath);
+ llapi_err_noerrno(LLAPI_MSG_ERROR,
+ "PCC: '%s' is not a valid FID", fidname);
return rc;
}
- rc = ioctl(fd, LL_IOC_PCC_DETACH_BY_FID, &detach);
- close(fd);
+ llapi_printf(LLAPI_MSG_DEBUG, "Handle the file: %s\n", fidname);
+ rc = ioctl(hsc->hsc_mntfd, LL_IOC_PCC_DETACH_BY_FID, &detach);
if (rc) {
llapi_printf(LLAPI_MSG_DEBUG,
"failed to detach file: %s\n", fidname);
static int llapi_pcc_del_internal(const char *mntpath, const char *pccpath,
enum hsmtool_type type, __u32 flags)
{
- struct hsm_scan_control hsc;
+ struct hsm_scan_control hsc = {
+ .hsc_type = type,
+ .hsc_mntpath = mntpath,
+ .hsc_hsmpath = pccpath,
+ .hsc_mntfd = -1,
+ .hsc_func = llapi_pcc_scan_detach,
+ .hsc_errnum = 0,
+ };
char cmd[PATH_MAX];
int rc;
if (flags & PCC_CLEANUP_FL_KEEP_DATA)
return 0;
- hsc.hsc_type = type;
- hsc.hsc_mntpath = mntpath;
- hsc.hsc_hsmpath = pccpath;
- hsc.hsc_func = llapi_pcc_scan_detach;
- hsc.hsc_errnum = 0;
+ hsc.hsc_mntfd = open(mntpath, O_RDONLY);
+ if (hsc.hsc_mntfd < 0) {
+ rc = -errno;
+ llapi_error(LLAPI_MSG_ERROR, rc,
+ "cannot open '%s'", mntpath);
+ return rc;
+ }
+
rc = hsm_scan_process(&hsc);
+ close(hsc.hsc_mntfd);
return rc;
}