From: Mikhail Pershin Date: Mon, 24 Sep 2012 21:08:57 +0000 (+0400) Subject: LU-1302 llog: llog ioctl to use env X-Git-Tag: 2.3.51~27 X-Git-Url: https://git.whamcloud.com/?a=commitdiff_plain;h=f7d5a7441211570fab2489f6b72f5d6641228316;hp=0d43b8d1b0d68701ac408fe5d131a9dca3a2d25b;p=fs%2Flustre-release.git LU-1302 llog: llog ioctl to use env Update llog_ioctl.c to use lu_env Signed-off-by: Mikhail Pershin Change-Id: I8f5476cccacae2d4922ac9af87d334929c0eba6c Reviewed-on: http://review.whamcloud.com/4094 Tested-by: Hudson Tested-by: Maloo Reviewed-by: wangdi Reviewed-by: Andreas Dilger Reviewed-by: Alex Zhuravlev --- diff --git a/lustre/include/lustre_log.h b/lustre/include/lustre_log.h index a4c131b..850d0e7 100644 --- a/lustre/include/lustre_log.h +++ b/lustre/include/lustre_log.h @@ -226,7 +226,8 @@ int obd_llog_init(struct obd_device *obd, struct obd_llog_group *olg, int obd_llog_finish(struct obd_device *obd, int count); /* llog_ioctl.c */ -int llog_ioctl(struct llog_ctxt *ctxt, int cmd, struct obd_ioctl_data *data); +int llog_ioctl(const struct lu_env *env, struct llog_ctxt *ctxt, int cmd, + struct obd_ioctl_data *data); int llog_catalog_list(struct obd_device *obd, int count, struct obd_ioctl_data *data); @@ -356,6 +357,13 @@ int llog_get_cat_list(struct obd_device *disk_obd, int llog_put_cat_list(struct obd_device *disk_obd, char *name, int idx, int count, struct llog_catid *idarray); +/* llog_osd.c */ +extern struct llog_operations llog_osd_ops; +int llog_osd_get_cat_list(const struct lu_env *env, struct dt_device *d, + int idx, int count, struct llog_catid *idarray); +int llog_osd_put_cat_list(const struct lu_env *env, struct dt_device *d, + int idx, int count, struct llog_catid *idarray); + #define LLOG_CTXT_FLAG_UNINITIALIZED 0x00000001 #define LLOG_CTXT_FLAG_STOP 0x00000002 diff --git a/lustre/mdc/mdc_request.c b/lustre/mdc/mdc_request.c index 3864f01..c17d2c8 100644 --- a/lustre/mdc/mdc_request.c +++ b/lustre/mdc/mdc_request.c @@ -1494,7 +1494,7 @@ static int mdc_iocontrol(unsigned int cmd, struct obd_export *exp, int len, case OBD_IOC_LLOG_INFO: case OBD_IOC_LLOG_PRINT: { ctxt = llog_get_context(obd, LLOG_CONFIG_REPL_CTXT); - rc = llog_ioctl(ctxt, cmd, data); + rc = llog_ioctl(NULL, ctxt, cmd, data); llog_ctxt_put(ctxt); GOTO(out, rc); } diff --git a/lustre/mgs/mgs_handler.c b/lustre/mgs/mgs_handler.c index 5b88b0c..29b7ab7 100644 --- a/lustre/mgs/mgs_handler.c +++ b/lustre/mgs/mgs_handler.c @@ -995,13 +995,12 @@ out_free: case OBD_IOC_LLOG_INFO: case OBD_IOC_LLOG_PRINT: { struct llog_ctxt *ctxt; - ctxt = llog_get_context(mgs->mgs_obd, LLOG_CONFIG_ORIG_CTXT); - - push_ctxt(&saved, &ctxt->loc_exp->exp_obd->obd_lvfs_ctxt, NULL); - rc = llog_ioctl(ctxt, cmd, data); - pop_ctxt(&saved, &ctxt->loc_exp->exp_obd->obd_lvfs_ctxt, NULL); - llog_ctxt_put(ctxt); + ctxt = llog_get_context(mgs->mgs_obd, LLOG_CONFIG_ORIG_CTXT); + push_ctxt(&saved, &ctxt->loc_exp->exp_obd->obd_lvfs_ctxt, NULL); + rc = llog_ioctl(NULL, ctxt, cmd, data); + pop_ctxt(&saved, &ctxt->loc_exp->exp_obd->obd_lvfs_ctxt, NULL); + llog_ctxt_put(ctxt); break; } diff --git a/lustre/obdclass/llog_internal.h b/lustre/obdclass/llog_internal.h index 524053b..5c91774 100644 --- a/lustre/obdclass/llog_internal.h +++ b/lustre/obdclass/llog_internal.h @@ -84,6 +84,7 @@ int llog_cat_id2handle(const struct lu_env *env, struct llog_handle *cathandle, int class_config_dump_handler(const struct lu_env *env, struct llog_handle *handle, struct llog_rec_hdr *rec, void *data); +int class_config_parse_rec(struct llog_rec_hdr *rec, char *buf, int size); int llog_process_or_fork(const struct lu_env *env, struct llog_handle *loghandle, llog_cb_t cb, void *data, void *catdata, bool fork); diff --git a/lustre/obdclass/llog_ioctl.c b/lustre/obdclass/llog_ioctl.c index c209cca..5a52065 100644 --- a/lustre/obdclass/llog_ioctl.c +++ b/lustre/obdclass/llog_ioctl.c @@ -27,7 +27,7 @@ * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2011, Whamcloud, Inc. + * Copyright (c) 2011, 2012, Intel, Inc. */ /* * This file is part of Lustre, http://www.lustre.org/ @@ -38,7 +38,6 @@ #include #include -#include #include "llog_internal.h" static int str2logid(struct llog_logid *logid, char *str, int len) @@ -94,9 +93,8 @@ static int llog_check_cb(const struct lu_env *env, struct llog_handle *handle, int cur_index, rc = 0; ENTRY; - cur_index = rec->lrh_index; - if (ioc_data && (ioc_data->ioc_inllen1)) { + if (ioc_data && ioc_data->ioc_inllen1 > 0) { l = 0; remains = ioc_data->ioc_inllen4 + cfs_size_round(ioc_data->ioc_inllen1) + @@ -110,11 +108,14 @@ static int llog_check_cb(const struct lu_env *env, struct llog_handle *handle, 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); - } + } + + cur_index = rec->lrh_index; + if (cur_index < from) + RETURN(0); + if (to > 0 && cur_index > to) + RETURN(-LLOG_EEMPTY); + if (handle->lgh_hdr->llh_flags & LLOG_F_IS_CAT) { struct llog_logid_rec *lir = (struct llog_logid_rec *)rec; struct llog_handle *log_handle; @@ -127,8 +128,7 @@ static int llog_check_cb(const struct lu_env *env, struct llog_handle *handle, } if (handle->lgh_ctxt == NULL) RETURN(-EOPNOTSUPP); - rc = llog_cat_id2handle(env, handle, &log_handle, - &lir->lid_id); + rc = llog_cat_id2handle(env, handle, &log_handle, &lir->lid_id); if (rc) { CDEBUG(D_IOCTL, "cannot find log #"LPX64"#"LPX64"#%08x\n", @@ -139,40 +139,35 @@ static int llog_check_cb(const struct lu_env *env, struct llog_handle *handle, rc = llog_process(env, log_handle, llog_check_cb, NULL, NULL); llog_close(env, log_handle); } else { + bool ok; + switch (rec->lrh_type) { case OST_SZ_REC: case MDS_UNLINK_REC: + case MDS_UNLINK64_REC: case MDS_SETATTR64_REC: case OBD_CFG_REC: - case LLOG_HDR_MAGIC: { - l = snprintf(out, remains, "[index]: %05d [type]: " - "%02x [len]: %04d ok\n", - cur_index, rec->lrh_type, - rec->lrh_len); - out += l; - remains -= l; - if (remains <= 0) { - CERROR("no space to print log records\n"); - RETURN(-LLOG_EEMPTY); - } - RETURN(0); - } - default: { - l = snprintf(out, remains, "[index]: %05d [type]: " - "%02x [len]: %04d failed\n", - cur_index, rec->lrh_type, - rec->lrh_len); - out += l; - remains -= l; - if (remains <= 0) { - CERROR("no space to print log records\n"); - RETURN(-LLOG_EEMPTY); - } - RETURN(0); - } - } - } - RETURN(rc); + case LLOG_GEN_REC: + case LLOG_HDR_MAGIC: + ok = true; + break; + default: + ok = false; + } + + l = snprintf(out, remains, "[index]: %05d [type]: " + "%02x [len]: %04d %s\n", + cur_index, rec->lrh_type, rec->lrh_len, + ok ? "ok" : "failed"); + out += l; + remains -= l; + if (remains <= 0) { + CERROR("%s: no space to print log records\n", + handle->lgh_ctxt->loc_obd->obd_name); + RETURN(-LLOG_EEMPTY); + } + } + RETURN(rc); } static int llog_print_cb(const struct lu_env *env, struct llog_handle *handle, @@ -185,7 +180,7 @@ static int llog_print_cb(const struct lu_env *env, struct llog_handle *handle, int cur_index; ENTRY; - if (ioc_data->ioc_inllen1) { + if (ioc_data != NULL && ioc_data->ioc_inllen1 > 0) { l = 0; remains = ioc_data->ioc_inllen4 + cfs_size_round(ioc_data->ioc_inllen1) + @@ -219,11 +214,17 @@ static int llog_print_cb(const struct lu_env *env, struct llog_handle *handle, "[index]: %05d [logid]: #"LPX64"#"LPX64"#%08x\n", cur_index, lir->lid_id.lgl_oid, lir->lid_id.lgl_oseq, lir->lid_id.lgl_ogen); - } else { - l = snprintf(out, remains, - "[index]: %05d [type]: %02x [len]: %04d\n", - cur_index, rec->lrh_type, - rec->lrh_len); + } else if (rec->lrh_type == OBD_CFG_REC) { + int rc; + + rc = class_config_parse_rec(rec, out, remains); + if (rc < 0) + RETURN(rc); + l = rc; + } else { + l = snprintf(out, remains, + "[index]: %05d [type]: %02x [len]: %04d\n", + cur_index, rec->lrh_type, rec->lrh_len); } out += l; remains -= l; @@ -283,42 +284,44 @@ static int llog_delete_cb(const struct lu_env *env, struct llog_handle *handle, } -int llog_ioctl(struct llog_ctxt *ctxt, int cmd, struct obd_ioctl_data *data) +int llog_ioctl(const struct lu_env *env, struct llog_ctxt *ctxt, int cmd, + struct obd_ioctl_data *data) { - struct llog_logid logid; - int err = 0; - struct llog_handle *handle = NULL; + struct llog_logid logid; + int rc = 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_open(NULL, ctxt, &handle, &logid, NULL, - LLOG_OPEN_EXISTS); - if (err) - GOTO(out, err); - } else if (*data->ioc_inlbuf1 == '$') { - char *name = data->ioc_inlbuf1 + 1; - - err = llog_open(NULL, ctxt, &handle, NULL, name, - LLOG_OPEN_EXISTS); - if (err) - GOTO(out, err); - } else { - GOTO(out, err = -EINVAL); - } + ENTRY; - err = llog_init_handle(NULL, handle, 0, NULL); - if (err) - GOTO(out_close, err = -ENOENT); + if (*data->ioc_inlbuf1 == '#') { + rc = str2logid(&logid, data->ioc_inlbuf1, data->ioc_inllen1); + if (rc) + RETURN(rc); + rc = llog_open(env, ctxt, &handle, &logid, NULL, + LLOG_OPEN_EXISTS); + if (rc) + RETURN(rc); + } else if (*data->ioc_inlbuf1 == '$') { + char *name = data->ioc_inlbuf1 + 1; + + rc = llog_open(env, ctxt, &handle, NULL, name, + LLOG_OPEN_EXISTS); + if (rc) + RETURN(rc); + } else { + RETURN(-EINVAL); + } + + rc = llog_init_handle(env, handle, 0, NULL); + if (rc) + GOTO(out_close, rc = -ENOENT); - switch (cmd) { - case OBD_IOC_LLOG_INFO: { - int l; - int remains = data->ioc_inllen2 + - cfs_size_round(data->ioc_inllen1); - char *out = data->ioc_bulk; + switch (cmd) { + case OBD_IOC_LLOG_INFO: { + int l; + int remains = data->ioc_inllen2 + + cfs_size_round(data->ioc_inllen1); + char *out = data->ioc_bulk; l = snprintf(out, remains, "logid: #"LPX64"#"LPX64"#%08x\n" @@ -334,99 +337,96 @@ int llog_ioctl(struct llog_ctxt *ctxt, int cmd, struct obd_ioctl_data *data) 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(NULL, 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(NULL, handle, class_config_dump_handler, - data, NULL); - if (err == -LLOG_EEMPTY) - err = 0; - else - err = llog_process(NULL, 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; + if (remains <= 0) { + CERROR("%s: not enough space for log header info\n", + ctxt->loc_obd->obd_name); + rc = -ENOSPC; + } + break; + } + case OBD_IOC_LLOG_CHECK: + LASSERT(data->ioc_inllen1 > 0); + rc = llog_process(env, handle, llog_check_cb, data, NULL); + if (rc == -LLOG_EEMPTY) + rc = 0; + else if (rc) + GOTO(out_close, rc); + break; + case OBD_IOC_LLOG_PRINT: + LASSERT(data->ioc_inllen1 > 0); + rc = llog_process(env, handle, llog_print_cb, data, NULL); + if (rc == -LLOG_EEMPTY) + rc = 0; + else if (rc) + GOTO(out_close, rc); + break; + 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); + cookie.lgc_index = simple_strtoul(data->ioc_inlbuf3, &endp, 0); + if (*endp != '\0') + GOTO(out_close, rc = -EINVAL); if (handle->lgh_hdr->llh_flags & LLOG_F_IS_PLAIN) { - err = llog_cancel_rec(NULL, handle, cookie.lgc_index); - GOTO(out_close, err); + rc = llog_cancel_rec(NULL, handle, cookie.lgc_index); + GOTO(out_close, rc); } else if (!(handle->lgh_hdr->llh_flags & LLOG_F_IS_CAT)) { - GOTO(out_close, err = -EINVAL); + GOTO(out_close, rc = -EINVAL); } if (data->ioc_inlbuf2 == NULL) /* catalog but no logid */ - GOTO(out_close, err = -ENOTTY); + GOTO(out_close, rc = -ENOTTY); - err = str2logid(&plain, data->ioc_inlbuf2, data->ioc_inllen2); - if (err) - GOTO(out_close, err); + rc = str2logid(&plain, data->ioc_inlbuf2, data->ioc_inllen2); + if (rc) + GOTO(out_close, rc); cookie.lgc_lgl = plain; - err = llog_cat_cancel_records(NULL, handle, 1, &cookie); - if (err) - GOTO(out_close, err); + rc = llog_cat_cancel_records(env, handle, 1, &cookie); + if (rc) + GOTO(out_close, rc); break; - } - case OBD_IOC_LLOG_REMOVE: { - struct llog_logid plain; + } + case OBD_IOC_LLOG_REMOVE: { + struct llog_logid plain; - if (handle->lgh_hdr->llh_flags & LLOG_F_IS_PLAIN) { - err = llog_destroy(NULL, handle); - GOTO(out_close, err); + if (handle->lgh_hdr->llh_flags & LLOG_F_IS_PLAIN) { + rc = llog_destroy(env, handle); + GOTO(out_close, rc); } else if (!(handle->lgh_hdr->llh_flags & LLOG_F_IS_CAT)) { - GOTO(out_close, err = -EINVAL); + GOTO(out_close, rc = -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(NULL, handle, &plain); + if (data->ioc_inlbuf2 > 0) { + /* remove indicate log from the catalog */ + rc = str2logid(&plain, data->ioc_inlbuf2, + data->ioc_inllen2); + if (rc) + GOTO(out_close, rc); + rc = llog_remove_log(env, handle, &plain); } else { /* remove all the log of the catalog */ - err = llog_process(NULL, handle, llog_delete_cb, NULL, - NULL); - if (err) - GOTO(out_close, err); + rc = llog_process(env, handle, llog_delete_cb, NULL, + NULL); + if (rc) + GOTO(out_close, rc); } break; } default: CERROR("%s: Unknown ioctl cmd %#x\n", ctxt->loc_obd->obd_name, cmd); - GOTO(out_close, err = -ENOTTY); - } + GOTO(out_close, rc = -ENOTTY); + } out_close: if (handle->lgh_hdr && handle->lgh_hdr->llh_flags & LLOG_F_IS_CAT) - llog_cat_close(NULL, handle); + llog_cat_close(env, handle); else - llog_close(NULL, handle); -out: - RETURN(err); + llog_close(env, handle); + RETURN(rc); } EXPORT_SYMBOL(llog_ioctl); diff --git a/lustre/obdclass/obd_config.c b/lustre/obdclass/obd_config.c index c48bd9e..b848d9f 100644 --- a/lustre/obdclass/obd_config.c +++ b/lustre/obdclass/obd_config.c @@ -1514,7 +1514,8 @@ static int class_config_llog_handler(const struct lu_env *env, } out: if (rc) { - CERROR("Err %d on cfg command:\n", rc); + CERROR("%s: cfg command failed: rc = %d\n", + handle->lgh_ctxt->loc_obd->obd_name, rc); class_config_dump_handler(NULL, handle, rec, data); } RETURN(rc); @@ -1559,65 +1560,80 @@ parse_out: } EXPORT_SYMBOL(class_config_parse_llog); +/** + * parse config record and output dump in supplied buffer. + * This is separated from class_config_dump_handler() to use + * for ioctl needs as well + */ +int class_config_parse_rec(struct llog_rec_hdr *rec, char *buf, int size) +{ + struct lustre_cfg *lcfg = (struct lustre_cfg *)(rec + 1); + char *ptr = buf; + char *end = buf + size; + int rc = 0; + + ENTRY; + + LASSERT(rec->lrh_type == OBD_CFG_REC); + rc = lustre_cfg_sanity_check(lcfg, rec->lrh_len); + if (rc < 0) + RETURN(rc); + + ptr += snprintf(ptr, end-ptr, "cmd=%05x ", lcfg->lcfg_command); + if (lcfg->lcfg_flags) + ptr += snprintf(ptr, end-ptr, "flags=%#08x ", + lcfg->lcfg_flags); + + if (lcfg->lcfg_num) + ptr += snprintf(ptr, end-ptr, "num=%#08x ", lcfg->lcfg_num); + + if (lcfg->lcfg_nid) + ptr += snprintf(ptr, end-ptr, "nid=%s("LPX64")\n ", + libcfs_nid2str(lcfg->lcfg_nid), + lcfg->lcfg_nid); + + if (lcfg->lcfg_command == LCFG_MARKER) { + struct cfg_marker *marker = lustre_cfg_buf(lcfg, 1); + + ptr += snprintf(ptr, end-ptr, "marker=%d(%#x)%s '%s'", + marker->cm_step, marker->cm_flags, + marker->cm_tgtname, marker->cm_comment); + } else { + int i; + + for (i = 0; i < lcfg->lcfg_bufcount; i++) { + ptr += snprintf(ptr, end-ptr, "%d:%s ", i, + lustre_cfg_string(lcfg, i)); + } + } + /* return consumed bytes */ + rc = ptr - buf; + RETURN(rc); +} + int class_config_dump_handler(const struct lu_env *env, struct llog_handle *handle, struct llog_rec_hdr *rec, void *data) { - int cfg_len = rec->lrh_len; - char *cfg_buf = (char*) (rec + 1); - char *outstr, *ptr, *end; - int rc = 0; - ENTRY; + char *outstr; + int rc = 0; - OBD_ALLOC(outstr, 256); - end = outstr + 256; - ptr = outstr; - if (!outstr) { - RETURN(-ENOMEM); - } - if (rec->lrh_type == OBD_CFG_REC) { - struct lustre_cfg *lcfg; - int i; + ENTRY; - rc = lustre_cfg_sanity_check(cfg_buf, cfg_len); - if (rc) - GOTO(out, rc); - lcfg = (struct lustre_cfg *)cfg_buf; + OBD_ALLOC(outstr, 256); + if (outstr == NULL) + RETURN(-ENOMEM); - ptr += snprintf(ptr, end-ptr, "cmd=%05x ", - lcfg->lcfg_command); - if (lcfg->lcfg_flags) { - ptr += snprintf(ptr, end-ptr, "flags=%#08x ", - lcfg->lcfg_flags); - } - if (lcfg->lcfg_num) { - ptr += snprintf(ptr, end-ptr, "num=%#08x ", - lcfg->lcfg_num); - } - if (lcfg->lcfg_nid) { - ptr += snprintf(ptr, end-ptr, "nid=%s("LPX64")\n ", - libcfs_nid2str(lcfg->lcfg_nid), - lcfg->lcfg_nid); - } - if (lcfg->lcfg_command == LCFG_MARKER) { - struct cfg_marker *marker = lustre_cfg_buf(lcfg, 1); - ptr += snprintf(ptr, end-ptr, "marker=%d(%#x)%s '%s'", - marker->cm_step, marker->cm_flags, - marker->cm_tgtname, marker->cm_comment); - } else { - for (i = 0; i < lcfg->lcfg_bufcount; i++) { - ptr += snprintf(ptr, end-ptr, "%d:%s ", i, - lustre_cfg_string(lcfg, i)); - } - } - LCONSOLE(D_WARNING, " %s\n", outstr); - } else { - LCONSOLE(D_WARNING, "unhandled lrh_type: %#x\n", rec->lrh_type); - rc = -EINVAL; - } -out: - OBD_FREE(outstr, 256); - RETURN(rc); + if (rec->lrh_type == OBD_CFG_REC) { + class_config_parse_rec(rec, outstr, 256); + LCONSOLE(D_WARNING, " %s\n", outstr); + } else { + LCONSOLE(D_WARNING, "unhandled lrh_type: %#x\n", rec->lrh_type); + rc = -EINVAL; + } + + OBD_FREE(outstr, 256); + RETURN(rc); } int class_config_dump_llog(struct llog_ctxt *ctxt, char *name,