X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=blobdiff_plain;f=lustre%2Fobdclass%2Fllog_ioctl.c;h=5c1c71461526107ce72054d3bac8ae2b3c7ee355;hp=97e801ec107231974ca5eeda4623c9cd54b47027;hb=3ac7c325efaf3a2537fafc79168d87de67982acd;hpb=e3a7c58aebafce40323db54bf6056029e5af4a70 diff --git a/lustre/obdclass/llog_ioctl.c b/lustre/obdclass/llog_ioctl.c index 97e801e..5c1c714 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/ @@ -36,13 +36,8 @@ #define DEBUG_SUBSYSTEM S_LOG -#ifndef EXPORT_SYMTAB -#define EXPORT_SYMTAB -#endif - #include #include -#include #include "llog_internal.h" static int str2logid(struct llog_logid *logid, char *str, int len) @@ -88,8 +83,8 @@ static int str2logid(struct llog_logid *logid, char *str, int len) RETURN(0); } -static int llog_check_cb(struct llog_handle *handle, struct llog_rec_hdr *rec, - void *data) +static int llog_check_cb(const struct lu_env *env, 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; @@ -98,9 +93,8 @@ static int llog_check_cb(struct llog_handle *handle, struct llog_rec_hdr *rec, 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) + @@ -114,11 +108,14 @@ static int llog_check_cb(struct llog_handle *handle, struct llog_rec_hdr *rec, 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; @@ -131,7 +128,7 @@ static int llog_check_cb(struct llog_handle *handle, struct llog_rec_hdr *rec, } if (handle->lgh_ctxt == NULL) RETURN(-EOPNOTSUPP); - rc = llog_cat_id2handle(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,49 +136,42 @@ static int llog_check_cb(struct llog_handle *handle, struct llog_rec_hdr *rec, lir->lid_id.lgl_ogen); RETURN(rc); } - rc = llog_process(log_handle, llog_check_cb, NULL, NULL); - llog_close(log_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 OST_RAID1_REC: case MDS_UNLINK_REC: - case MDS_SETATTR_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(struct llog_handle *handle, struct llog_rec_hdr *rec, - void *data) +static int llog_print_cb(const struct lu_env *env, 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; @@ -190,7 +180,7 @@ static int llog_print_cb(struct llog_handle *handle, struct llog_rec_hdr *rec, 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) + @@ -214,6 +204,7 @@ static int llog_print_cb(struct llog_handle *handle, struct llog_rec_hdr *rec, if (handle->lgh_hdr->llh_flags & LLOG_F_IS_CAT) { struct llog_logid_rec *lir = (struct llog_logid_rec *)rec; + if (rec->lrh_type != LLOG_LOGID_MAGIC) { CERROR("invalid record in catalog\n"); RETURN(-EINVAL); @@ -223,11 +214,17 @@ static int llog_print_cb(struct llog_handle *handle, struct llog_rec_hdr *rec, "[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; @@ -238,14 +235,15 @@ 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) +static int llog_remove_log(const struct lu_env *env, struct llog_handle *cat, + struct llog_logid *logid) { struct llog_handle *log; int rc, index = 0; ENTRY; - cfs_down_write(&cat->lgh_lock); - rc = llog_cat_id2handle(cat, &log, logid); + + rc = llog_cat_id2handle(env, cat, &log, logid); if (rc) { CDEBUG(D_IOCTL, "cannot find log #"LPX64"#"LPX64"#%08x\n", logid->lgl_oid, logid->lgl_oseq, logid->lgl_ogen); @@ -254,68 +252,76 @@ static int llog_remove_log(struct llog_handle *cat, struct llog_logid *logid) 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); + rc = llog_destroy(env, log); + if (rc) { + CDEBUG(D_IOCTL, "cannot destroy log\n"); + GOTO(out, rc); + } + down_write(&cat->lgh_lock); + if (cat->u.chd.chd_current_log == log) + cat->u.chd.chd_current_log = NULL; + up_write(&cat->lgh_lock); + llog_cat_set_first_idx(cat, index); + rc = llog_cancel_rec(env, cat, index); out: - llog_free_handle(log); - cfs_up_write(&cat->lgh_lock); - RETURN(rc); + llog_close(env, log); + RETURN(rc); } -static int llog_delete_cb(struct llog_handle *handle, struct llog_rec_hdr *rec, - void *data) +static int llog_delete_cb(const struct lu_env *env, struct llog_handle *handle, + struct llog_rec_hdr *rec, void *data) { - struct llog_logid_rec *lir = (struct llog_logid_rec*)rec; - int rc; + 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); + ENTRY; + if (rec->lrh_type != LLOG_LOGID_MAGIC) + RETURN(-EINVAL); + rc = llog_remove_log(env, handle, &lir->lid_id); - RETURN(rc); + RETURN(rc); } -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; - - 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 + - cfs_size_round(data->ioc_inllen1); - char *out = data->ioc_bulk; + struct llog_logid logid; + int rc = 0; + struct llog_handle *handle = NULL; + + ENTRY; + + 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; l = snprintf(out, remains, "logid: #"LPX64"#"LPX64"#%08x\n" @@ -331,95 +337,100 @@ 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(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) { - cfs_down_write(&handle->lgh_lock); - err = llog_cancel_rec(handle, cookie.lgc_index); - cfs_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); - } - } + 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, rc = -EINVAL); + + if (handle->lgh_hdr->llh_flags & LLOG_F_IS_PLAIN) { + 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, rc = -EINVAL); + } + + if (data->ioc_inlbuf2 == NULL) /* catalog but no logid */ + GOTO(out_close, rc = -ENOTTY); + + rc = str2logid(&plain, data->ioc_inlbuf2, data->ioc_inllen2); + if (rc) + GOTO(out_close, rc); + cookie.lgc_lgl = plain; + 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; + + 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, rc = -EINVAL); + } + + 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 */ + 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, rc = -ENOTTY); + } 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); + if (handle->lgh_hdr && + handle->lgh_hdr->llh_flags & LLOG_F_IS_CAT) + llog_cat_close(env, handle); + else + llog_close(env, handle); + RETURN(rc); } EXPORT_SYMBOL(llog_ioctl); +#ifdef HAVE_LDISKFS_OSD int llog_catalog_list(struct obd_device *obd, int count, struct obd_ioctl_data *data) { @@ -437,7 +448,7 @@ int llog_catalog_list(struct obd_device *obd, int count, if (!idarray) RETURN(-ENOMEM); - cfs_mutex_lock(&obd->obd_olg.olg_cat_processing); + mutex_lock(&obd->obd_olg.olg_cat_processing); rc = llog_get_cat_list(obd, name, 0, count, idarray); if (rc) GOTO(out, rc); @@ -458,10 +469,11 @@ int llog_catalog_list(struct obd_device *obd, int count, } out: /* release semaphore */ - cfs_mutex_unlock(&obd->obd_olg.olg_cat_processing); + mutex_unlock(&obd->obd_olg.olg_cat_processing); OBD_FREE_LARGE(idarray, size); RETURN(rc); } EXPORT_SYMBOL(llog_catalog_list); +#endif