Whamcloud - gitweb
add llog_check and add remove the logs of catalog in llog_remove r:peter
authorwangdi <wangdi>
Tue, 9 Dec 2003 13:00:35 +0000 (13:00 +0000)
committerwangdi <wangdi>
Tue, 9 Dec 2003 13:00:35 +0000 (13:00 +0000)
lustre/include/linux/lustre_lib.h
lustre/mds/mds_lov.c
lustre/obdclass/class_obd.c
lustre/obdclass/llog_ioctl.c
lustre/utils/lctl.c
lustre/utils/obd.c

index 2a70b02..b95e847 100644 (file)
@@ -447,6 +447,7 @@ static inline void obd_ioctl_freedata(char *buf, int len)
 #define OBD_IOC_LLOG_PRINT             _IOWR('f', 192, long)
 #define OBD_IOC_LLOG_CANCEL            _IOWR('f', 193, long)
 #define OBD_IOC_LLOG_REMOVE            _IOWR('f', 194, long)
+#define OBD_IOC_LLOG_CHECK             _IOWR('f', 195, long)
 
 #define ECHO_IOC_GET_STRIPE            _IOWR('f', 200, long)
 #define ECHO_IOC_SET_STRIPE            _IOWR('f', 201, long)
index f4ad74c..81fa3e5 100644 (file)
@@ -462,8 +462,9 @@ int mds_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
                 RETURN(rc);
 
         }
+        case OBD_IOC_LLOG_CHECK: 
         case OBD_IOC_LLOG_CANCEL:
-        case OBD_IOC_LLOG_REMOVE: {
+        case OBD_IOC_LLOG_REMOVE: { 
                 struct llog_ctxt *ctxt = 
                         llog_get_context(obd, LLOG_CONFIG_ORIG_CTXT);
 
index 40561ac..3f72012 100644 (file)
@@ -240,6 +240,7 @@ int class_handle_ioctl(struct obd_class_user_state *ocus, unsigned int cmd,
         case OBD_IOC_LLOG_INFO:
         case OBD_IOC_LLOG_PRINT:
         case OBD_IOC_LLOG_CANCEL:
+        case OBD_IOC_LLOG_CHECK:
         case OBD_IOC_LLOG_REMOVE:
                 break;
         default:
index 03279f8..a9c4d4c 100644 (file)
@@ -60,6 +60,89 @@ static int str2logid(struct llog_logid *logid, char *str, int len)
         RETURN(0);
 }
 
+int llog_check_cb(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 char *out;
+        char *endp;
+        int cur_index, rc = 0;
+        
+        cur_index = le32_to_cpu(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);
+                from = simple_strtol(ioc_data->ioc_inlbuf2, &endp, 0);
+                if (*endp != '\0')
+                        RETURN(-EINVAL);
+                to = simple_strtol(ioc_data->ioc_inlbuf3, &endp, 0);
+                if (*endp != '\0')
+                        RETURN(-EINVAL);
+                ioc_data->ioc_inllen1 = 0;
+                out = ioc_data->ioc_bulk;
+                if (cur_index < from)
+                        RETURN(0);
+                if (to > 0 && cur_index > to)
+                        RETURN(-LLOG_EEMPTY);
+        }
+        if (le32_to_cpu(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 (le32_to_cpu(rec->lrh_type) != LLOG_LOGID_MAGIC) { 
+                        l = snprintf(out, remains,
+                                     "[index]: %05d  [type]: %02x  [len]: %04d failed\n", 
+                                     cur_index, le32_to_cpu(rec->lrh_type),
+                                     le32_to_cpu(rec->lrh_len));
+                }
+                if (handle->lgh_ctxt == NULL)
+                        RETURN(-EOPNOTSUPP);
+                llog_cat_id2handle(handle, &log_handle, &lir->lid_id);
+                rc = llog_process(log_handle, llog_check_cb, NULL); 
+                llog_close(log_handle);
+        } else {
+                switch (le32_to_cpu(rec->lrh_type)) {
+                case OST_SZ_REC:
+                case OST_RAID1_REC:    
+                case MDS_UNLINK_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", 
+                                     cur_index, le32_to_cpu(rec->lrh_type),
+                                     le32_to_cpu(rec->lrh_len));
+                         out += l;
+                         remains -= l;
+                         if (remains <= 0) {
+                                CERROR("not enough space for print log records\n");
+                                RETURN(-LLOG_EEMPTY);
+                         }
+                         RETURN(0);
+                }
+                default: {
+                         l = snprintf(out, remains,
+                                     "[index]: %05d  [type]: %02x  [len]: %04d failed\n", 
+                                     cur_index, le32_to_cpu(rec->lrh_type),
+                                     le32_to_cpu(rec->lrh_len));
+                         out += l;
+                         remains -= l;
+                         if (remains <= 0) {
+                                CERROR("not enough space for print log records\n");
+                                RETURN(-LLOG_EEMPTY);
+                         }
+                         RETURN(0);
+                } 
+                }
+        }
+        RETURN(rc);
+}
+
 static int llog_print_cb(struct llog_handle *handle, struct llog_rec_hdr *rec, 
                          void *data)
 {
@@ -117,7 +200,6 @@ static int llog_print_cb(struct llog_handle *handle, struct llog_rec_hdr *rec,
 
         RETURN(0);
 }
-
 static int llog_remove_log(struct llog_handle *cat, struct llog_logid *logid)
 {
         struct llog_handle *log;
@@ -140,10 +222,24 @@ 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);
         RETURN(rc);
 
 }
+int llog_delete_cb(struct llog_handle *handle, struct llog_rec_hdr *rec, 
+                         void *data)
+{
+        struct  llog_logid_rec *lir = (struct llog_logid_rec*)rec;
+        int     rc;
+        
+        if (le32_to_cpu(rec->lrh_type) != LLOG_LOGID_MAGIC)
+              return (-EINVAL); 
+        rc = llog_remove_log(handle, &lir->lid_id);
+        
+        RETURN(rc);
+}
+
 
 int llog_ioctl(struct llog_ctxt *ctxt, int cmd, struct obd_ioctl_data *data)
 {
@@ -197,6 +293,14 @@ int llog_ioctl(struct llog_ctxt *ctxt, int cmd, struct obd_ioctl_data *data)
 
                 GOTO(out_close, err);
         }
+        case OBD_IOC_LLOG_CHECK: {
+                LASSERT(data->ioc_inllen1);
+                err = llog_process(handle, llog_check_cb, data);
+                if (err == -LLOG_EEMPTY)
+                        err = 0;
+                GOTO(out_close, err);
+        }
+
         case OBD_IOC_LLOG_PRINT: {
                 LASSERT(data->ioc_inllen1);
                 err = llog_process(handle, llog_print_cb, data);
@@ -210,7 +314,7 @@ int llog_ioctl(struct llog_ctxt *ctxt, int cmd, struct obd_ioctl_data *data)
                 struct llog_logid plain;
                 char *endp;
                 
-                if (!le32_to_cpu(handle->lgh_hdr->llh_flags) & LLOG_F_IS_CAT)
+                if (!(le32_to_cpu(handle->lgh_hdr->llh_flags) & LLOG_F_IS_CAT))
                         GOTO(out_close, err = -EINVAL);
         
                 err = str2logid(&plain, data->ioc_inlbuf2, data->ioc_inllen2);
@@ -228,13 +332,19 @@ int llog_ioctl(struct llog_ctxt *ctxt, int cmd, struct obd_ioctl_data *data)
         case OBD_IOC_LLOG_REMOVE: {
                 struct llog_logid plain;
                 
-                if (!le32_to_cpu(handle->lgh_hdr->llh_flags) & LLOG_F_IS_CAT)
+                if (!(le32_to_cpu(handle->lgh_hdr->llh_flags) & LLOG_F_IS_CAT))
                         GOTO(out_close, err = -EINVAL);
         
-                err = str2logid(&plain, data->ioc_inlbuf2, data->ioc_inllen2);
-                if (err)
-                        GOTO(out_close, err);
-                err = llog_remove_log(handle, &plain);
+                if (data->ioc_inlbuf2) {
+                        /*remove indicate log from the catalog*/
+                        err = str2logid(&plain, data->ioc_inlbuf2, data->ioc_inllen2);
+                        if (err)
+                                GOTO(out_close, err);
+                        err = llog_remove_log(handle, &plain);
+                } else {
+                        /*remove all the log of the catalog*/
+                        llog_process(handle, llog_delete_cb, NULL);
+                }
                 GOTO(out_close, err);
         }
         }
index 3c4c0ad..c9d69aa 100644 (file)
@@ -245,7 +245,12 @@ command_t cmdlist[] = {
          "usage: llog_print <$logname|#oid#ogr#ogen> [from] [to]\n"
          "       oid, ogr and ogen are hexadecimal.\n"
          "       print all records from index 1 by default."},
-        {"llog_cancel", jt_llog_cancel, 0,
+        {"llog_check", jt_llog_check, 0,
+         "print log content information.\n"
+         "usage: llog_check <$logname|#oid#ogr#ogen> [from] [to]\n"
+         "       oid, ogr and ogen are hexadecimal.\n"
+         "       check all records from index 1 by default."},
+         {"llog_cancel", jt_llog_cancel, 0,
          "cancel one record in log.\n"
          "usage: llog_cancel <catlog id|catlog name> <log id> <index>"},
         {"llog_remove", jt_llog_remove, 0,
index 4ff1326..a3f6c80 100644 (file)
@@ -1937,26 +1937,68 @@ int jt_llog_cancel(int argc, char **argv)
         return rc;
 
 }
+int jt_llog_check(int argc, char **argv)
+{
+        struct obd_ioctl_data data;
+        int rc;
+
+        if (argc != 2 && argc != 4)
+                return CMD_HELP;
+
+        IOC_INIT(data);
+        data.ioc_inllen1 = strlen(argv[1]) + 1;
+        data.ioc_inlbuf1 = argv[1];
+        if (argc == 4) {
+                data.ioc_inllen2 = strlen(argv[2]) + 1;
+                data.ioc_inlbuf2 = argv[2];
+                data.ioc_inllen3 = strlen(argv[3]) + 1;
+                data.ioc_inlbuf3 = argv[3];
+        } else {
+                char from[2] = "1", to[3] = "-1";
+                data.ioc_inllen2 = strlen(from) + 1;
+                data.ioc_inlbuf2 = from;
+                data.ioc_inllen3 = strlen(to) + 1;
+                data.ioc_inlbuf3 = to;
+        }
+        data.ioc_inllen4 = max - size_round(sizeof(data)) -
+                size_round(data.ioc_inllen1) -
+                size_round(data.ioc_inllen2) -
+                size_round(data.ioc_inllen3);
+        IOC_PACK(argv[0], data);
+
+        rc = l_ioctl(OBD_DEV_ID, OBD_IOC_LLOG_CHECK, buf);
+        if (rc == 0)
+                fprintf(stdout, "%s", ((struct obd_ioctl_data*)buf)->ioc_bulk);
+        else
+                fprintf(stderr, "OBD_IOC_LLOG_CHECK failed: %s\n",
+                        strerror(errno));
+        return rc;
+}
 
 int jt_llog_remove(int argc, char **argv)
 {
         struct obd_ioctl_data data;
         int rc;
 
-        if (argc != 3)
+        if (argc != 3 && argc != 2)
                 return CMD_HELP;
 
         IOC_INIT(data);
         data.ioc_inllen1 = strlen(argv[1]) + 1;
         data.ioc_inlbuf1 = argv[1];
-        data.ioc_inllen2 = strlen(argv[2]) + 1;
-        data.ioc_inlbuf2 = argv[2];
+        if (argc == 3){
+                data.ioc_inllen2 = strlen(argv[2]) + 1;
+                data.ioc_inlbuf2 = argv[2];
+        }
         IOC_PACK(argv[0], data);
 
         rc = l_ioctl(OBD_DEV_ID, OBD_IOC_LLOG_REMOVE, buf);
-        if (rc == 0)
-                fprintf(stdout, "log %s are removed.\n", argv[2]);
-        else
+        if (rc == 0) {
+                if (argc == 3)
+                        fprintf(stdout, "log %s are removed.\n", argv[2]);
+                else
+                        fprintf(stdout, "the log in catlog %s are removed. \n", argv[1]);
+        } else
                 fprintf(stderr, "OBD_IOC_LLOG_REMOVE failed: %s\n",
                         strerror(errno));