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)
{
RETURN(0);
}
-
static int llog_remove_log(struct llog_handle *cat, struct llog_logid *logid)
{
struct llog_handle *log;
}
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)
{
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);
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);
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);
}
}
"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,
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));