Whamcloud - gitweb
LU-911 osd: OI is implemented internally within OSD
[fs/lustre-release.git] / lustre / obdclass / llog_ioctl.c
index 6c060e7..aa91695 100644 (file)
@@ -1,9 +1,39 @@
 /* -*- 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.
+ * GPL HEADER START
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 only,
+ * as published by the Free Software Foundation.
+ *
+ * This program 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 GNU
+ * General Public License version 2 for more details (a copy is included
+ * in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License
+ * version 2 along with this program; If not, see
+ * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ *
+ * GPL HEADER END
+ */
+/*
+ * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Use is subject to license terms.
+ *
+ * Copyright (c) 2011, Whamcloud, Inc.
+ */
+/*
+ * This file is part of Lustre, http://www.lustre.org/
+ * Lustre is a trademark of Sun Microsystems, Inc.
  */
 
 #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);
@@ -46,7 +76,7 @@ static int str2logid(struct llog_logid *logid, char *str, int len)
                 RETURN(-EINVAL);
 
         *end = '\0';
-        logid->lgl_ogr = simple_strtoull(start, &endp, 0);
+        logid->lgl_oseq = simple_strtoull(start, &endp, 0);
         if (endp != end)
                 RETURN(-EINVAL);
 
@@ -69,14 +99,15 @@ 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)) {
                 l = 0;
                 remains = ioc_data->ioc_inllen4 +
-                        size_round(ioc_data->ioc_inllen1) +
-                        size_round(ioc_data->ioc_inllen2) +
-                        size_round(ioc_data->ioc_inllen3);
+                        cfs_size_round(ioc_data->ioc_inllen1) +
+                        cfs_size_round(ioc_data->ioc_inllen2) +
+                        cfs_size_round(ioc_data->ioc_inllen3);
                 from = simple_strtol(ioc_data->ioc_inlbuf2, &endp, 0);
                 if (*endp != '\0')
                         RETURN(-EINVAL);
@@ -102,7 +133,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_oseq,
+                               lir->lid_id.lgl_ogen);
+                        RETURN(rc);
+                }
                 rc = llog_process(log_handle, llog_check_cb, NULL, NULL);
                 llog_close(log_handle);
         } else {
@@ -110,8 +148,9 @@ 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 MDS_SETATTR64_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,12 +191,13 @@ 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 +
-                        size_round(ioc_data->ioc_inllen1) +
-                        size_round(ioc_data->ioc_inllen2) +
-                        size_round(ioc_data->ioc_inllen3);
+                        cfs_size_round(ioc_data->ioc_inllen1) +
+                        cfs_size_round(ioc_data->ioc_inllen2) +
+                        cfs_size_round(ioc_data->ioc_inllen3);
                 from = simple_strtol(ioc_data->ioc_inlbuf2, &endp, 0);
                 if (*endp != '\0')
                         RETURN(-EINVAL);
@@ -184,7 +224,7 @@ static int llog_print_cb(struct llog_handle *handle, struct llog_rec_hdr *rec,
                 l = snprintf(out, remains,
                              "[index]: %05d  [logid]: #"LPX64"#"LPX64"#%08x\n",
                              cur_index, lir->lid_id.lgl_oid,
-                             lir->lid_id.lgl_ogr, lir->lid_id.lgl_ogen);
+                             lir->lid_id.lgl_oseq, lir->lid_id.lgl_ogen);
         } else {
                 l = snprintf(out, remains,
                              "[index]: %05d  [type]: %02x  [len]: %04d\n",
@@ -205,11 +245,12 @@ static int llog_remove_log(struct llog_handle *cat, struct llog_logid *logid)
         struct llog_handle *log;
         int rc, index = 0;
 
-        down_write(&cat->lgh_lock);
+        ENTRY;
+        cfs_down_write(&cat->lgh_lock);
         rc = llog_cat_id2handle(cat, &log, logid);
         if (rc) {
                 CDEBUG(D_IOCTL, "cannot find log #"LPX64"#"LPX64"#%08x\n",
-                       logid->lgl_oid, logid->lgl_ogr, logid->lgl_ogen);
+                       logid->lgl_oid, logid->lgl_oseq, logid->lgl_ogen);
                 GOTO(out, rc = -ENOENT);
         }
 
@@ -224,7 +265,7 @@ static int llog_remove_log(struct llog_handle *cat, struct llog_logid *logid)
         rc = llog_cancel_rec(cat, index);
 out:
         llog_free_handle(log);
-        up_write(&cat->lgh_lock);
+        cfs_up_write(&cat->lgh_lock);
         RETURN(rc);
 
 }
@@ -235,8 +276,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 +291,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)
@@ -273,7 +316,7 @@ int llog_ioctl(struct llog_ctxt *ctxt, int cmd, struct obd_ioctl_data *data)
         case OBD_IOC_LLOG_INFO: {
                 int l;
                 int remains = data->ioc_inllen2 +
-                        size_round(data->ioc_inllen1);
+                        cfs_size_round(data->ioc_inllen1);
                 char *out = data->ioc_bulk;
 
                 l = snprintf(out, remains,
@@ -281,7 +324,7 @@ int llog_ioctl(struct llog_ctxt *ctxt, int cmd, struct obd_ioctl_data *data)
                              "flags:            %x (%s)\n"
                              "records count:    %d\n"
                              "last index:       %d\n",
-                             handle->lgh_id.lgl_oid, handle->lgh_id.lgl_ogr,
+                             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 &
@@ -305,9 +348,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);
         }
@@ -321,9 +366,9 @@ int llog_ioctl(struct llog_ctxt *ctxt, int cmd, struct obd_ioctl_data *data)
                         GOTO(out_close, err = -EINVAL);
 
                 if (handle->lgh_hdr->llh_flags & LLOG_F_IS_CAT) {
-                        down_write(&handle->lgh_lock);
+                        cfs_down_write(&handle->lgh_lock);
                         err = llog_cancel_rec(handle, cookie.lgc_index);
-                        up_write(&handle->lgh_lock);
+                        cfs_up_write(&handle->lgh_lock);
                         GOTO(out_close, err);
                 }
 
@@ -341,7 +386,7 @@ 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 & cpu_to_le32(LLOG_F_IS_PLAIN)) {
+                if (handle->lgh_hdr->llh_flags & LLOG_F_IS_PLAIN) {
                         err = llog_destroy(handle);
                         if (!err)
                                 llog_free_handle(handle);
@@ -377,8 +422,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;
@@ -387,18 +432,17 @@ 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);
+        OBD_ALLOC_LARGE(idarray, size);
         if (!idarray)
                 RETURN(-ENOMEM);
-        memset(idarray, 0, size);
 
-        rc = llog_get_cat_list(obd, obd, name, count, idarray);
-        if (rc) {
-                OBD_FREE(idarray, size);
-                RETURN(rc);
-        }
+        cfs_mutex_down(&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;
@@ -406,7 +450,7 @@ int llog_catlog_list(struct obd_device *obd, int count,
                 id = &idarray[i].lci_logid;
                 l = snprintf(out, remains,
                              "catalog log: #"LPX64"#"LPX64"#%08x\n",
-                             id->lgl_oid, id->lgl_ogr, id->lgl_ogen);
+                             id->lgl_oid, id->lgl_oseq, id->lgl_ogen);
                 out += l;
                 remains -= l;
                 if (remains <= 0) {
@@ -414,8 +458,12 @@ int llog_catlog_list(struct obd_device *obd, int count,
                         break;
                 }
         }
-        OBD_FREE(idarray, size);
-        RETURN(0);
+out:
+        /* release semaphore */
+        cfs_mutex_up(&obd->obd_olg.olg_cat_processing);
+
+        OBD_FREE_LARGE(idarray, size);
+        RETURN(rc);
 
 }
-EXPORT_SYMBOL(llog_catlog_list);
+EXPORT_SYMBOL(llog_catalog_list);