llog_ioctl.c
来自「lustre 1.6.5 source code」· C语言 代码 · 共 453 行 · 第 1/2 页
C
453 行
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) { CDEBUG(D_IOCTL, "cannot find log #"LPX64"#"LPX64"#%08x\n", logid->lgl_oid, logid->lgl_ogr, logid->lgl_ogen); GOTO(out, rc = -ENOENT); } index = log->u.phd.phd_cookie.lgc_index; LASSERT(index); rc = llog_destroy(log); if (rc) { CDEBUG(D_IOCTL, "cannot destroy log\n"); GOTO(out, rc); } llog_cat_set_first_idx(cat, index); rc = llog_cancel_rec(cat, index);out: llog_free_handle(log); up_write(&cat->lgh_lock); RETURN(rc);}static 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; ENTRY; if (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){ struct llog_logid logid; int err = 0; struct llog_handle *handle = NULL; ENTRY; if (*data->ioc_inlbuf1 == '#') { err = str2logid(&logid, data->ioc_inlbuf1, data->ioc_inllen1); if (err) GOTO(out, err); err = llog_create(ctxt, &handle, &logid, NULL); if (err) GOTO(out, err); } else if (*data->ioc_inlbuf1 == '$') { char *name = data->ioc_inlbuf1 + 1; err = llog_create(ctxt, &handle, NULL, name); if (err) GOTO(out, err); } else { GOTO(out, err = -EINVAL); } err = llog_init_handle(handle, 0, NULL); if (err) GOTO(out_close, err = -ENOENT); switch (cmd) { case OBD_IOC_LLOG_INFO: { int l; int remains = data->ioc_inllen2 + 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_ogr, 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) CERROR("not enough space for log header info\n"); GOTO(out_close, err); } case OBD_IOC_LLOG_CHECK: { LASSERT(data->ioc_inllen1); err = llog_process(handle, llog_check_cb, data, NULL); if (err == -LLOG_EEMPTY) err = 0; GOTO(out_close, err); } case OBD_IOC_LLOG_PRINT: { LASSERT(data->ioc_inllen1); 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); } case OBD_IOC_LLOG_CANCEL: { struct llog_cookie cookie; struct llog_logid plain; char *endp; 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; if (!(handle->lgh_hdr->llh_flags & LLOG_F_IS_CAT)) GOTO(out_close, err = -EINVAL); err = llog_cat_cancel_records(handle, 1, &cookie); GOTO(out_close, err); } 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); 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, NULL); } GOTO(out_close, err); } }out_close: if (handle->lgh_hdr && handle->lgh_hdr->llh_flags & LLOG_F_IS_CAT) llog_cat_put(handle); else llog_close(handle);out: RETURN(err);}EXPORT_SYMBOL(llog_ioctl);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(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); } 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_ogr, id->lgl_ogen); out += l; remains -= l; if (remains <= 0) { CWARN("not enough memory for catlog list\n"); break; } } OBD_FREE(idarray, size); RETURN(0);}EXPORT_SYMBOL(llog_catalog_list);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?