Whamcloud - gitweb
Branch HEAD
[fs/lustre-release.git] / lustre / obdclass / llog_ioctl.c
index 14d20f2..bc8afc6 100644 (file)
@@ -1,9 +1,25 @@
 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
  * vim:expandtab:shiftwidth=8:tabstop=8:
  *
- *   You should have received a copy of the GNU General Public License
- *   along with Lustre; if not, write to the Free Software
- *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *  Copyright (C) 2005 Cluster File Systems, Inc.
+ *
+ *   This file is part of the Lustre file system, http://www.lustre.org
+ *   Lustre is a trademark of Cluster File Systems, Inc.
+ *
+ *   You may have signed or agreed to another license before downloading
+ *   this software.  If so, you are bound by the terms and conditions
+ *   of that agreement, and the following does not apply to you.  See the
+ *   LICENSE file included with this distribution for more information.
+ *
+ *   If you did not agree to a different license, then this copy of Lustre
+ *   is open source software; you can redistribute it and/or modify it
+ *   under the terms of version 2 of the GNU General Public License as
+ *   published by the Free Software Foundation.
+ *
+ *   In either case, Lustre is distributed in the hope that it will be
+ *   useful, but WITHOUT ANY WARRANTY; without even the implied warranty
+ *   of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   license text for more details.
  */
 
 #define DEBUG_SUBSYSTEM S_LOG
 #define EXPORT_SYMTAB
 #endif
 
-#include <linux/fs.h>
-#include <linux/obd_class.h>
-#include <linux/lustre_log.h>
-#include <portals/list.h>
+#include <obd_class.h>
+#include <lustre_log.h>
+#include <libcfs/list.h>
 #include "llog_internal.h"
 
 static int str2logid(struct llog_logid *logid, char *str, int len)
 {
         char *start, *end, *endp;
 
+        ENTRY;
         start = str;
         if (*start != '#')
                 RETURN(-EINVAL);
@@ -34,7 +50,7 @@ static int str2logid(struct llog_logid *logid, char *str, int len)
                 RETURN(-EINVAL);
 
         *end = '\0';
-        logid->lgl_oid = simple_strtoull(start, &endp, 16);
+        logid->lgl_oid = simple_strtoull(start, &endp, 0);
         if (endp != end)
                 RETURN(-EINVAL);
 
@@ -46,7 +62,7 @@ static int str2logid(struct llog_logid *logid, char *str, int len)
                 RETURN(-EINVAL);
 
         *end = '\0';
-        logid->lgl_ogr = simple_strtoull(start, &endp, 16);
+        logid->lgl_ogr = simple_strtoull(start, &endp, 0);
         if (endp != end)
                 RETURN(-EINVAL);
 
@@ -69,6 +85,7 @@ static int llog_check_cb(struct llog_handle *handle, struct llog_rec_hdr *rec,
         char *endp;
         int cur_index, rc = 0;
 
+        ENTRY;
         cur_index = rec->lrh_index;
 
         if (ioc_data && (ioc_data->ioc_inllen1)) {
@@ -102,7 +119,14 @@ static int llog_check_cb(struct llog_handle *handle, struct llog_rec_hdr *rec,
                 }
                 if (handle->lgh_ctxt == NULL)
                         RETURN(-EOPNOTSUPP);
-                llog_cat_id2handle(handle, &log_handle, &lir->lid_id);
+                rc = llog_cat_id2handle(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_ogr,
+                               lir->lid_id.lgl_ogen);
+                        RETURN(rc);
+                }
                 rc = llog_process(log_handle, llog_check_cb, NULL, NULL);
                 llog_close(log_handle);
         } else {
@@ -110,8 +134,8 @@ static int llog_check_cb(struct llog_handle *handle, struct llog_rec_hdr *rec,
                 case OST_SZ_REC:
                 case OST_RAID1_REC:
                 case MDS_UNLINK_REC:
+                case MDS_SETATTR_REC:
                 case OBD_CFG_REC:
-                case PTL_CFG_REC:
                 case LLOG_HDR_MAGIC: {
                          l = snprintf(out, remains, "[index]: %05d  [type]: "
                                       "%02x  [len]: %04d ok\n",
@@ -152,6 +176,7 @@ static int llog_print_cb(struct llog_handle *handle, struct llog_rec_hdr *rec,
         char *endp;
         int cur_index;
 
+        ENTRY;
         if (ioc_data->ioc_inllen1) {
                 l = 0;
                 remains = ioc_data->ioc_inllen4 +
@@ -205,6 +230,7 @@ static int llog_remove_log(struct llog_handle *cat, struct llog_logid *logid)
         struct llog_handle *log;
         int rc, index = 0;
 
+        ENTRY;
         down_write(&cat->lgh_lock);
         rc = llog_cat_id2handle(cat, &log, logid);
         if (rc) {
@@ -235,8 +261,9 @@ static int llog_delete_cb(struct llog_handle *handle, struct llog_rec_hdr *rec,
         struct  llog_logid_rec *lir = (struct llog_logid_rec*)rec;
         int     rc;
 
+        ENTRY;
         if (rec->lrh_type != LLOG_LOGID_MAGIC)
-              return (-EINVAL);
+              RETURN (-EINVAL);
         rc = llog_remove_log(handle, &lir->lid_id);
 
         RETURN(rc);
@@ -249,6 +276,7 @@ int llog_ioctl(struct llog_ctxt *ctxt, int cmd, struct obd_ioctl_data *data)
         int err = 0;
         struct llog_handle *handle = NULL;
 
+        ENTRY;
         if (*data->ioc_inlbuf1 == '#') {
                 err = str2logid(&logid, data->ioc_inlbuf1, data->ioc_inllen1);
                 if (err)
@@ -305,9 +333,11 @@ int llog_ioctl(struct llog_ctxt *ctxt, int cmd, struct obd_ioctl_data *data)
 
         case OBD_IOC_LLOG_PRINT: {
                 LASSERT(data->ioc_inllen1);
-                err = llog_process(handle, llog_print_cb, data, NULL);
+                err = llog_process(handle, class_config_dump_handler,data,NULL);
                 if (err == -LLOG_EEMPTY)
                         err = 0;
+                else
+                        err = llog_process(handle, llog_print_cb, data, NULL);
 
                 GOTO(out_close, err);
         }
@@ -316,15 +346,23 @@ int llog_ioctl(struct llog_ctxt *ctxt, int cmd, struct obd_ioctl_data *data)
                 struct llog_logid plain;
                 char *endp;
 
-                if (!(handle->lgh_hdr->llh_flags & LLOG_F_IS_CAT))
+                cookie.lgc_index = simple_strtoul(data->ioc_inlbuf3, &endp, 0);
+                if (*endp != '\0')
                         GOTO(out_close, err = -EINVAL);
 
+                if (handle->lgh_hdr->llh_flags & LLOG_F_IS_CAT) {
+                        down_write(&handle->lgh_lock);
+                        err = llog_cancel_rec(handle, cookie.lgc_index);
+                        up_write(&handle->lgh_lock);
+                        GOTO(out_close, err);
+                }
+
                 err = str2logid(&plain, data->ioc_inlbuf2, data->ioc_inllen2);
                 if (err)
                         GOTO(out_close, err);
                 cookie.lgc_lgl = plain;
-                cookie.lgc_index = simple_strtoul(data->ioc_inlbuf3, &endp, 0);
-                if (*endp != '\0')
+
+                if (!(handle->lgh_hdr->llh_flags & LLOG_F_IS_CAT))
                         GOTO(out_close, err = -EINVAL);
 
                 err = llog_cat_cancel_records(handle, 1, &cookie);
@@ -333,6 +371,13 @@ int llog_ioctl(struct llog_ctxt *ctxt, int cmd, struct obd_ioctl_data *data)
         case OBD_IOC_LLOG_REMOVE: {
                 struct llog_logid plain;
 
+                if (handle->lgh_hdr->llh_flags & LLOG_F_IS_PLAIN) {
+                        err = llog_destroy(handle);
+                        if (!err)
+                                llog_free_handle(handle);
+                        GOTO(out, err);
+                }
+
                 if (!(handle->lgh_hdr->llh_flags & LLOG_F_IS_CAT))
                         GOTO(out_close, err = -EINVAL);
 
@@ -362,8 +407,8 @@ out:
 }
 EXPORT_SYMBOL(llog_ioctl);
 
-int llog_catlog_list(struct obd_device *obd, int count,
-                     struct obd_ioctl_data *data)
+int llog_catalog_list(struct obd_device *obd, int count,
+                      struct obd_ioctl_data *data)
 {
         int size, i;
         struct llog_catid *idarray;
@@ -372,6 +417,7 @@ int llog_catlog_list(struct obd_device *obd, int count,
         char *out;
         int l, remains, rc = 0;
 
+        ENTRY;
         size = sizeof(*idarray) * count;
 
         OBD_ALLOC(idarray, size);
@@ -403,4 +449,4 @@ int llog_catlog_list(struct obd_device *obd, int count,
         RETURN(0);
 
 }
-EXPORT_SYMBOL(llog_catlog_list);
+EXPORT_SYMBOL(llog_catalog_list);