Whamcloud - gitweb
LU-3069 build: fix 'integer handling' issues
[fs/lustre-release.git] / lustre / obdclass / llog_ioctl.c
index 92d3d8b..9de449f 100644 (file)
@@ -27,7 +27,7 @@
  * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
  *
- * Copyright (c) 2011, 2012, Intel Corporation.
+ * Copyright (c) 2011, 2013, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
@@ -43,6 +43,7 @@
 static int str2logid(struct llog_logid *logid, char *str, int len)
 {
         char *start, *end, *endp;
+       __u64 id, seq;
 
         ENTRY;
         start = str;
@@ -57,7 +58,7 @@ static int str2logid(struct llog_logid *logid, char *str, int len)
                 RETURN(-EINVAL);
 
         *end = '\0';
-        logid->lgl_oid = simple_strtoull(start, &endp, 0);
+       id = simple_strtoull(start, &endp, 0);
         if (endp != end)
                 RETURN(-EINVAL);
 
@@ -69,11 +70,14 @@ static int str2logid(struct llog_logid *logid, char *str, int len)
                 RETURN(-EINVAL);
 
         *end = '\0';
-        logid->lgl_oseq = simple_strtoull(start, &endp, 0);
+       seq = simple_strtoull(start, &endp, 0);
         if (endp != end)
                 RETURN(-EINVAL);
 
-        start = ++end;
+       ostid_set_seq(&logid->lgl_oi, seq);
+       ostid_set_id(&logid->lgl_oi, id);
+
+       start = ++end;
         if (start - str >= len - 1)
                 RETURN(-EINVAL);
         logid->lgl_ogen = simple_strtoul(start, &endp, 16);
@@ -87,7 +91,8 @@ static int llog_check_cb(const struct lu_env *env, struct llog_handle *handle,
                         struct llog_rec_hdr *rec, void *data)
 {
         struct obd_ioctl_data *ioc_data = (struct obd_ioctl_data *)data;
-        static int l, remains, from, to;
+       static int l, remains;
+       static long from, to;
         static char *out;
         char *endp;
         int cur_index, rc = 0;
@@ -116,9 +121,9 @@ static int llog_check_cb(const struct lu_env *env, struct llog_handle *handle,
        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;
-                struct llog_handle *log_handle;
+       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]: "
@@ -128,17 +133,16 @@ static int llog_check_cb(const struct lu_env *env, struct llog_handle *handle,
                 }
                 if (handle->lgh_ctxt == NULL)
                         RETURN(-EOPNOTSUPP);
-               rc = llog_cat_id2handle(env, handle, &log_handle, &lir->lid_id);
-                if (rc) {
-                        CDEBUG(D_IOCTL,
-                               "cannot find log #"LPX64"#"LPX64"#%08x\n",
-                               lir->lid_id.lgl_oid, lir->lid_id.lgl_oseq,
-                               lir->lid_id.lgl_ogen);
-                        RETURN(rc);
-                }
-               rc = llog_process(env, log_handle, llog_check_cb, NULL, NULL);
-               llog_close(env, log_handle);
-        } else {
+               rc = llog_cat_id2handle(env, handle, &loghandle, &lir->lid_id);
+               if (rc) {
+                       CDEBUG(D_IOCTL, "cannot find log #"DOSTID"#%08x\n",
+                              POSTID(&lir->lid_id.lgl_oi),
+                              lir->lid_id.lgl_ogen);
+                       RETURN(rc);
+               }
+               rc = llog_process(env, loghandle, llog_check_cb, NULL, NULL);
+               llog_handle_put(loghandle);
+       } else {
                bool ok;
 
                 switch (rec->lrh_type) {
@@ -174,7 +178,8 @@ static int llog_print_cb(const struct lu_env *env, struct llog_handle *handle,
                         struct llog_rec_hdr *rec, void *data)
 {
         struct obd_ioctl_data *ioc_data = (struct obd_ioctl_data *)data;
-        static int l, remains, from, to;
+       static int l, remains;
+       static long from, to;
         static char *out;
         char *endp;
         int cur_index;
@@ -210,10 +215,10 @@ static int llog_print_cb(const struct lu_env *env, struct llog_handle *handle,
                         RETURN(-EINVAL);
                 }
 
-                l = snprintf(out, remains,
-                             "[index]: %05d  [logid]: #"LPX64"#"LPX64"#%08x\n",
-                             cur_index, lir->lid_id.lgl_oid,
-                             lir->lid_id.lgl_oseq, lir->lid_id.lgl_ogen);
+               l = snprintf(out, remains,
+                            "[index]: %05d  [logid]: #"DOSTID"#%08x\n",
+                            cur_index, POSTID(&lir->lid_id.lgl_oi),
+                            lir->lid_id.lgl_ogen);
        } else if (rec->lrh_type == OBD_CFG_REC) {
                int rc;
 
@@ -238,33 +243,26 @@ static int llog_print_cb(const struct lu_env *env, struct llog_handle *handle,
 static int llog_remove_log(const struct lu_env *env, struct llog_handle *cat,
                           struct llog_logid *logid)
 {
-        struct llog_handle *log;
-        int rc, index = 0;
+       struct llog_handle      *log;
+       int                      rc;
 
-        ENTRY;
+       ENTRY;
 
        rc = llog_cat_id2handle(env, cat, &log, logid);
-        if (rc) {
-                CDEBUG(D_IOCTL, "cannot find log #"LPX64"#"LPX64"#%08x\n",
-                       logid->lgl_oid, logid->lgl_oseq, logid->lgl_ogen);
-                GOTO(out, rc = -ENOENT);
-        }
+       if (rc) {
+               CDEBUG(D_IOCTL, "cannot find log #"DOSTID"#%08x\n",
+                      POSTID(&logid->lgl_oi), logid->lgl_ogen);
+               RETURN(-ENOENT);
+       }
 
-        index = log->u.phd.phd_cookie.lgc_index;
-        LASSERT(index);
        rc = llog_destroy(env, log);
        if (rc) {
                CDEBUG(D_IOCTL, "cannot destroy log\n");
                GOTO(out, rc);
        }
-       down_write(&cat->lgh_lock);
-       if (cat->u.chd.chd_current_log == log)
-               cat->u.chd.chd_current_log = NULL;
-       up_write(&cat->lgh_lock);
-       llog_cat_set_first_idx(cat, index);
-       rc = llog_cancel_rec(env, cat, index);
+       llog_cat_cleanup(env, cat, log, log->u.phd.phd_cookie.lgc_index);
 out:
-       llog_close(env, log);
+       llog_handle_put(log);
        RETURN(rc);
 
 }
@@ -323,18 +321,18 @@ int llog_ioctl(const struct lu_env *env, struct llog_ctxt *ctxt, int cmd,
                                   cfs_size_round(data->ioc_inllen1);
                char    *out = data->ioc_bulk;
 
-                l = snprintf(out, remains,
-                             "logid:            #"LPX64"#"LPX64"#%08x\n"
-                             "flags:            %x (%s)\n"
-                             "records count:    %d\n"
-                             "last index:       %d\n",
-                             handle->lgh_id.lgl_oid, handle->lgh_id.lgl_oseq,
-                             handle->lgh_id.lgl_ogen,
-                             handle->lgh_hdr->llh_flags,
-                             handle->lgh_hdr->llh_flags &
-                             LLOG_F_IS_CAT ? "cat" : "plain",
-                             handle->lgh_hdr->llh_count,
-                             handle->lgh_last_idx);
+               l = snprintf(out, remains,
+                            "logid:            #"DOSTID"#%08x\n"
+                            "flags:            %x (%s)\n"
+                            "records count:    %d\n"
+                            "last index:       %d\n",
+                            POSTID(&handle->lgh_id.lgl_oi),
+                            handle->lgh_id.lgl_ogen,
+                            handle->lgh_hdr->llh_flags,
+                            handle->lgh_hdr->llh_flags &
+                            LLOG_F_IS_CAT ? "cat" : "plain",
+                            handle->lgh_hdr->llh_count,
+                            handle->lgh_last_idx);
                 out += l;
                 remains -= l;
                if (remains <= 0) {
@@ -429,51 +427,3 @@ out_close:
        RETURN(rc);
 }
 EXPORT_SYMBOL(llog_ioctl);
-
-#ifdef HAVE_LDISKFS_OSD
-int llog_catalog_list(struct obd_device *obd, int count,
-                      struct obd_ioctl_data *data)
-{
-        int size, i;
-        struct llog_catid *idarray;
-        struct llog_logid *id;
-        char name[32] = CATLIST;
-        char *out;
-        int l, remains, rc = 0;
-
-        ENTRY;
-        size = sizeof(*idarray) * count;
-
-        OBD_ALLOC_LARGE(idarray, size);
-        if (!idarray)
-                RETURN(-ENOMEM);
-
-       mutex_lock(&obd->obd_olg.olg_cat_processing);
-        rc = llog_get_cat_list(obd, name, 0, count, idarray);
-        if (rc)
-                GOTO(out, rc);
-
-        out = data->ioc_bulk;
-        remains = data->ioc_inllen1;
-        for (i = 0; i < count; i++) {
-                id = &idarray[i].lci_logid;
-                l = snprintf(out, remains,
-                             "catalog log: #"LPX64"#"LPX64"#%08x\n",
-                             id->lgl_oid, id->lgl_oseq, id->lgl_ogen);
-                out += l;
-                remains -= l;
-                if (remains <= 0) {
-                        CWARN("not enough memory for catlog list\n");
-                        break;
-                }
-        }
-out:
-        /* release semaphore */
-       mutex_unlock(&obd->obd_olg.olg_cat_processing);
-
-        OBD_FREE_LARGE(idarray, size);
-        RETURN(rc);
-
-}
-EXPORT_SYMBOL(llog_catalog_list);
-#endif