Whamcloud - gitweb
LU-14398 llapi: simplify llapi_fid2path()
[fs/lustre-release.git] / lustre / obdclass / llog_ioctl.c
index 4350450..11478a5 100644 (file)
@@ -48,20 +48,24 @@ static int str2logid(struct llog_logid *logid, char *str, int len)
        start = str;
        if (start[0] == '[') {
                struct lu_fid *fid = &logid->lgl_oi.oi_fid;
+               struct lu_fid sfid;
                int num;
 
                fid_zero(fid);
                logid->lgl_ogen = 0;
                num = sscanf(start + 1, SFID, RFID(fid));
                CDEBUG(D_INFO, DFID":%x\n", PFID(fid), logid->lgl_ogen);
-               RETURN(num == 3 && fid_is_sane(fid) ? 0 : -EINVAL);
+               logid_to_fid(logid, &sfid);
+               RETURN(num == 3 && fid_is_sane(&sfid) ? 0 : -EINVAL);
        }
 
 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(3, 1, 53, 0)
-       /* logids used to be input in the form "#id#seq:ogen" before they
+       /*
+        * logids used to be input in the form "#id#seq:ogen" before they
         * were changed over to accept the FID [seq:oid:ver] format.
         * This is accepted for compatibility reasons, though I doubt
-        * anyone is actually using this for anything. */
+        * anyone is actually using this for anything.
+        */
        if (start[0] != '#')
                RETURN(-EINVAL);
 
@@ -95,8 +99,8 @@ static int str2logid(struct llog_logid *logid, char *str, int len)
                RETURN(-EINVAL);
 
        start = ++end;
-        if (start - str >= len - 1)
-                RETURN(-EINVAL);
+       if (start - str >= len - 1)
+               RETURN(-EINVAL);
 
        rc = kstrtouint(start, 16, &ogen);
        if (rc)
@@ -146,17 +150,17 @@ static int llog_check_cb(const struct lu_env *env, struct llog_handle *handle,
                RETURN(-LLOG_EEMPTY);
 
        if (handle->lgh_hdr->llh_flags & LLOG_F_IS_CAT) {
-               struct llog_logid_rec   *lir = (struct llog_logid_rec *)rec;
-               struct llog_handle      *loghandle;
-
-                if (rec->lrh_type != LLOG_LOGID_MAGIC) {
-                        l = snprintf(out, remains, "[index]: %05d  [type]: "
-                                     "%02x  [len]: %04d failed\n",
-                                     cur_index, rec->lrh_type,
-                                     rec->lrh_len);
-                }
-                if (handle->lgh_ctxt == NULL)
-                        RETURN(-EOPNOTSUPP);
+               struct llog_logid_rec *lir = (struct llog_logid_rec *)rec;
+               struct llog_handle *loghandle;
+
+               if (rec->lrh_type != LLOG_LOGID_MAGIC) {
+                       l = snprintf(out, remains,
+                                    "[index]: %05d  [type]: %02x  [len]: %04d failed\n",
+                                    cur_index, rec->lrh_type,
+                                    rec->lrh_len);
+               }
+               if (handle->lgh_ctxt == NULL)
+                       RETURN(-EOPNOTSUPP);
                rc = llog_cat_id2handle(env, handle, &loghandle, &lir->lid_id);
                if (rc) {
                        CDEBUG(D_IOCTL, "cannot find log "DFID":%x\n",
@@ -165,16 +169,16 @@ static int llog_check_cb(const struct lu_env *env, struct llog_handle *handle,
                        RETURN(rc);
                }
                rc = llog_process(env, loghandle, llog_check_cb, NULL, NULL);
-               llog_handle_put(loghandle);
+               llog_handle_put(env, loghandle);
        } else {
                bool ok;
 
-                switch (rec->lrh_type) {
-                case OST_SZ_REC:
-                case MDS_UNLINK_REC:
+               switch (rec->lrh_type) {
+               case OST_SZ_REC:
+               case MDS_UNLINK_REC:
                case MDS_UNLINK64_REC:
-                case MDS_SETATTR64_REC:
-                case OBD_CFG_REC:
+               case MDS_SETATTR64_REC:
+               case OBD_CFG_REC:
                case LLOG_GEN_REC:
                case LLOG_HDR_MAGIC:
                        ok = true;
@@ -228,19 +232,19 @@ static int llog_print_cb(const struct lu_env *env, struct llog_handle *handle,
                ioc_data->ioc_inllen1 = 0;
        }
 
-        cur_index = rec->lrh_index;
-        if (cur_index < from)
-                RETURN(0);
-        if (to > 0 && cur_index > to)
-                RETURN(-LLOG_EEMPTY);
+       cur_index = rec->lrh_index;
+       if (cur_index < from)
+               RETURN(0);
+       if (to > 0 && cur_index > to)
+               RETURN(-LLOG_EEMPTY);
 
-        if (handle->lgh_hdr->llh_flags & LLOG_F_IS_CAT) {
-                struct llog_logid_rec *lir = (struct llog_logid_rec *)rec;
+       if (handle->lgh_hdr->llh_flags & LLOG_F_IS_CAT) {
+               struct llog_logid_rec *lir = (struct llog_logid_rec *)rec;
 
-                if (rec->lrh_type != LLOG_LOGID_MAGIC) {
-                        CERROR("invalid record in catalog\n");
-                        RETURN(-EINVAL);
-                }
+               if (rec->lrh_type != LLOG_LOGID_MAGIC) {
+                       CERROR("invalid record in catalog\n");
+                       RETURN(-EINVAL);
+               }
 
                l = snprintf(out, remains,
                             "[index]: %05d  [logid]: "DFID":%x\n",
@@ -257,21 +261,21 @@ static int llog_print_cb(const struct lu_env *env, struct llog_handle *handle,
                l = snprintf(out, remains,
                             "[index]: %05d  [type]: %02x  [len]: %04d\n",
                             cur_index, rec->lrh_type, rec->lrh_len);
-        }
-        out += l;
-        remains -= l;
-        if (remains <= 0) {
-                CERROR("not enough space for print log records\n");
-                RETURN(-LLOG_EEMPTY);
-        }
-
-        RETURN(0);
+       }
+       out += l;
+       remains -= l;
+       if (remains <= 0) {
+               CERROR("not enough space for print log records\n");
+               RETURN(-LLOG_EEMPTY);
+       }
+
+       RETURN(0);
 }
 static int llog_remove_log(const struct lu_env *env, struct llog_handle *cat,
                           struct llog_logid *logid)
 {
-       struct llog_handle      *log;
-       int                      rc;
+       struct llog_handle *log;
+       int rc;
 
        ENTRY;
 
@@ -290,7 +294,7 @@ static int llog_remove_log(const struct lu_env *env, struct llog_handle *cat,
        }
        llog_cat_cleanup(env, cat, log, log->u.phd.phd_cookie.lgc_index);
 out:
-       llog_handle_put(log);
+       llog_handle_put(env, log);
        RETURN(rc);
 
 }
@@ -298,8 +302,8 @@ out:
 static int llog_delete_cb(const struct lu_env *env, struct llog_handle *handle,
                          struct llog_rec_hdr *rec, void *data)
 {
-       struct llog_logid_rec   *lir = (struct llog_logid_rec *)rec;
-       int                      rc;
+       struct llog_logid_rec *lir = (struct llog_logid_rec *)rec;
+       int rc;
 
        ENTRY;
        if (rec->lrh_type != LLOG_LOGID_MAGIC)
@@ -313,15 +317,16 @@ static int llog_delete_cb(const struct lu_env *env, struct llog_handle *handle,
 int llog_ioctl(const struct lu_env *env, struct llog_ctxt *ctxt, int cmd,
               struct obd_ioctl_data *data)
 {
-       struct llog_logid        logid;
-       int                      rc = 0;
-       struct llog_handle      *handle = NULL;
-       char *logname;
+       struct llog_logid logid;
+       int rc = 0;
+       struct llog_handle *handle = NULL;
+       char *logname, start;
 
        ENTRY;
 
        logname = data->ioc_inlbuf1;
-       if (logname[0] == '#' || logname[0] == '[') {
+       start = logname[0];
+       if (start == '#' || start == '[') {
                rc = str2logid(&logid, logname, data->ioc_inllen1);
                if (rc)
                        RETURN(rc);
@@ -329,8 +334,8 @@ int llog_ioctl(const struct lu_env *env, struct llog_ctxt *ctxt, int cmd,
                               LLOG_OPEN_EXISTS);
                if (rc)
                        RETURN(rc);
-       } else if (logname[0] == '$' || isalpha(logname[0])) {
-               if (logname[0] == '$')
+       } else if (start == '$' || isalpha(start) || isdigit(start)) {
+               if (start == '$')
                        logname++;
 
                rc = llog_open(env, ctxt, &handle, NULL, logname,
@@ -338,7 +343,10 @@ int llog_ioctl(const struct lu_env *env, struct llog_ctxt *ctxt, int cmd,
                if (rc)
                        RETURN(rc);
        } else {
-               RETURN(-EINVAL);
+               rc = -EINVAL;
+               CDEBUG(D_INFO, "%s: invalid log name '%s': rc = %d\n",
+                     ctxt->loc_obd->obd_name, logname, rc);
+               RETURN(rc);
        }
 
        rc = llog_init_handle(env, handle, 0, NULL);
@@ -347,10 +355,10 @@ int llog_ioctl(const struct lu_env *env, struct llog_ctxt *ctxt, int cmd,
 
        switch (cmd) {
        case OBD_IOC_LLOG_INFO: {
-               int      l;
-               int      remains = data->ioc_inllen2 +
+               int l;
+               int remains = data->ioc_inllen2 +
                                   cfs_size_round(data->ioc_inllen1);
-               char    *out = data->ioc_bulk;
+               char *out = data->ioc_bulk;
 
                l = snprintf(out, remains,
                             "logid:            "DFID":%x\n"
@@ -428,7 +436,7 @@ int llog_ioctl(const struct lu_env *env, struct llog_ctxt *ctxt, int cmd,
                        GOTO(out_close, rc = -EINVAL);
                }
 
-               if (data->ioc_inlbuf2 > 0) {
+               if (data->ioc_inlbuf2) {
                        /* remove indicate log from the catalog */
                        rc = str2logid(&plain, data->ioc_inlbuf2,
                                       data->ioc_inllen2);
@@ -464,11 +472,11 @@ int llog_catalog_list(const struct lu_env *env, struct dt_device *d,
                      int count, struct obd_ioctl_data *data,
                      const struct lu_fid *fid)
 {
-       int                      size, i;
-       struct llog_catid       *idarray;
-       struct llog_logid       *id;
-       char                    *out;
-       int                      l, remains, rc = 0;
+       int size, i;
+       struct llog_catid *idarray;
+       struct llog_logid *id;
+       char *out;
+       int l, remains, rc = 0;
 
        ENTRY;
 
@@ -491,15 +499,28 @@ int llog_catalog_list(const struct lu_env *env, struct dt_device *d,
 
        out = data->ioc_bulk;
        remains = data->ioc_inllen1;
-       for (i = 0; i < count; i++) {
+       /* OBD_FAIL: fetch the catalog records from the specified one */
+       if (OBD_FAIL_CHECK(OBD_FAIL_CATLIST))
+               data->ioc_count = cfs_fail_val - 1;
+       for (i = data->ioc_count; i < count; i++) {
                id = &idarray[i].lci_logid;
                l = snprintf(out, remains, "catalog_log: "DFID":%x\n",
-                            PFID(&id->lgl_oi.oi_fid), id->lgl_ogen);
+                             PFID(&id->lgl_oi.oi_fid), id->lgl_ogen);
                out += l;
                remains -= l;
-               if (remains <= 0)
-                       break;
+               if (remains <= 0) {
+                       if (remains < 0) {
+                               /* the print is not complete */
+                               remains += l;
+                               data->ioc_bulk[out - data->ioc_bulk - l] = '\0';
+                               data->ioc_count = i;
+                       } else {
+                               data->ioc_count = i++;
+                       }
+                       goto out;
+               }
        }
+       data->ioc_count = 0;
 out:
        OBD_FREE_LARGE(idarray, size);
        RETURN(rc);