From e87585ce9b9a9975e05e5b02623777b7322233f9 Mon Sep 17 00:00:00 2001 From: jacob Date: Wed, 10 Mar 2004 22:25:05 +0000 Subject: [PATCH] b=2325 r=robert fix llog_destroy to work with named logs --- lustre/ChangeLog | 1 + lustre/mds/mds_lov.c | 27 ++++++++++++++++++++++++++- lustre/obdclass/llog_ioctl.c | 25 ++++++++++++++++++++----- lustre/obdclass/llog_lvfs.c | 14 ++++++++++++++ lustre/obdclass/llog_test.c | 40 ++++++++++++++++++++++++++++++++++++++++ 5 files changed, 101 insertions(+), 6 deletions(-) diff --git a/lustre/ChangeLog b/lustre/ChangeLog index 3420d0d..d233e0c 100644 --- a/lustre/ChangeLog +++ b/lustre/ChangeLog @@ -6,6 +6,7 @@ tbd Cluster File Systems, Inc. - drop filter export grants atomically with removal from device (2663) - del obd_self_export from work_list in class_disconnect_exports (2908) - don't LBUG if MDS recovery times out during orphan cleanup (2530) + - fix destroying of named logs (2325) 2004-03-04 Cluster File Systems, Inc. * version 1.2.0 diff --git a/lustre/mds/mds_lov.c b/lustre/mds/mds_lov.c index 3520849..c6b6839 100644 --- a/lustre/mds/mds_lov.c +++ b/lustre/mds/mds_lov.c @@ -364,6 +364,27 @@ int mds_iocontrol(unsigned int cmd, struct obd_export *exp, int len, RETURN(rc); } + case OBD_IOC_CLEAR_LOG: { + char *name = data->ioc_inlbuf1; + if (mds->mds_cfg_llh) + RETURN(-EBUSY); + + push_ctxt(&saved, &obd->obd_ctxt, NULL); + rc = llog_create(llog_get_context(obd, LLOG_CONFIG_ORIG_CTXT), + &mds->mds_cfg_llh, NULL, name); + if (rc == 0) { + llog_init_handle(mds->mds_cfg_llh, LLOG_F_IS_PLAIN, + NULL); + + rc = llog_destroy(mds->mds_cfg_llh); + llog_free_handle(mds->mds_cfg_llh); + } + pop_ctxt(&saved, &obd->obd_ctxt, NULL); + + mds->mds_cfg_llh = NULL; + RETURN(rc); + } + case OBD_IOC_DORECORD: { char *cfg_buf; struct llog_rec_hdr rec; @@ -449,13 +470,17 @@ int mds_iocontrol(unsigned int cmd, struct obd_export *exp, int len, case OBD_IOC_LLOG_REMOVE: { struct llog_ctxt *ctxt = llog_get_context(obd, LLOG_CONFIG_ORIG_CTXT); + int rc2; obd_llog_finish(obd, mds->mds_lov_desc.ld_tgt_count); push_ctxt(&saved, &ctxt->loc_exp->exp_obd->obd_ctxt, NULL); rc = llog_ioctl(ctxt, cmd, data); pop_ctxt(&saved, &ctxt->loc_exp->exp_obd->obd_ctxt, NULL); llog_cat_initialize(obd, mds->mds_lov_desc.ld_tgt_count); - + rc2 = obd_set_info(mds->mds_osc_exp, strlen("mds_conn"), "mds_conn", + 0, NULL); + if (!rc) + rc = rc2; RETURN(rc); } case OBD_IOC_LLOG_INFO: diff --git a/lustre/obdclass/llog_ioctl.c b/lustre/obdclass/llog_ioctl.c index 14d20f2..6c060e7 100644 --- a/lustre/obdclass/llog_ioctl.c +++ b/lustre/obdclass/llog_ioctl.c @@ -34,7 +34,7 @@ static int str2logid(struct llog_logid *logid, char *str, int len) RETURN(-EINVAL); *end = '\0'; - logid->lgl_oid = simple_strtoull(start, &endp, 16); + logid->lgl_oid = simple_strtoull(start, &endp, 0); if (endp != end) RETURN(-EINVAL); @@ -46,7 +46,7 @@ static int str2logid(struct llog_logid *logid, char *str, int len) RETURN(-EINVAL); *end = '\0'; - logid->lgl_ogr = simple_strtoull(start, &endp, 16); + logid->lgl_ogr = simple_strtoull(start, &endp, 0); if (endp != end) RETURN(-EINVAL); @@ -316,15 +316,23 @@ int llog_ioctl(struct llog_ctxt *ctxt, int cmd, struct obd_ioctl_data *data) struct llog_logid plain; char *endp; - if (!(handle->lgh_hdr->llh_flags & LLOG_F_IS_CAT)) + 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; - cookie.lgc_index = simple_strtoul(data->ioc_inlbuf3, &endp, 0); - if (*endp != '\0') + + if (!(handle->lgh_hdr->llh_flags & LLOG_F_IS_CAT)) GOTO(out_close, err = -EINVAL); err = llog_cat_cancel_records(handle, 1, &cookie); @@ -333,6 +341,13 @@ int llog_ioctl(struct llog_ctxt *ctxt, int cmd, struct obd_ioctl_data *data) case OBD_IOC_LLOG_REMOVE: { struct llog_logid plain; + if (handle->lgh_hdr->llh_flags & cpu_to_le32(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); diff --git a/lustre/obdclass/llog_lvfs.c b/lustre/obdclass/llog_lvfs.c index ad0b562..ba8798a 100644 --- a/lustre/obdclass/llog_lvfs.c +++ b/lustre/obdclass/llog_lvfs.c @@ -532,10 +532,24 @@ static int llog_lvfs_close(struct llog_handle *handle) static int llog_lvfs_destroy(struct llog_handle *handle) { + struct dentry *fdentry; struct obdo *oa; int rc; ENTRY; + fdentry = handle->lgh_file->f_dentry; + if (!strcmp(fdentry->d_parent->d_name.name, "LOGS")) { + struct inode *inode = fdentry->d_parent->d_inode; + rc = llog_lvfs_close(handle); + if (rc) + RETURN(rc); + + down(&inode->i_sem); + rc = vfs_unlink(inode, fdentry); + up(&inode->i_sem); + RETURN(rc); + } + oa = obdo_alloc(); if (oa == NULL) RETURN(-ENOMEM); diff --git a/lustre/obdclass/llog_test.c b/lustre/obdclass/llog_test.c index f8e6de1..e3edd02 100644 --- a/lustre/obdclass/llog_test.c +++ b/lustre/obdclass/llog_test.c @@ -489,6 +489,42 @@ parse_out: RETURN(rc); } +static int llog_test_7(struct obd_device *obd) +{ + struct llog_ctxt *ctxt = llog_get_context(obd, LLOG_TEST_ORIG_CTXT); + struct llog_handle *llh; + struct llog_create_rec lcr; + char name[10]; + int rc; + ENTRY; + + sprintf(name, "%x", llog_test_rand+2); + CWARN("7: create a log with name: %s\n", name); + LASSERT(ctxt); + + rc = llog_create(ctxt, &llh, NULL, name); + if (rc) { + CERROR("7: llog_create with name %s failed: %d\n", name, rc); + RETURN(rc); + } + llog_init_handle(llh, LLOG_F_IS_PLAIN, &uuid); + + lcr.lcr_hdr.lrh_len = lcr.lcr_tail.lrt_len = cpu_to_le32(sizeof(lcr)); + lcr.lcr_hdr.lrh_type = cpu_to_le32(OST_SZ_REC); + rc = llog_write_rec(llh, &lcr.lcr_hdr, NULL, 0, NULL, -1); + if (rc) { + CERROR("7: write one log record failed: %d\n", rc); + RETURN(rc); + } + + rc = llog_destroy(llh); + if (rc) + CERROR("7: llog_destroy failed: %d\n", rc); + else + llog_free_handle(llh); + RETURN(rc); +} + /* ------------------------------------------------------------------------- * Tests above, boring obd functions below * ------------------------------------------------------------------------- */ @@ -529,6 +565,10 @@ static int llog_run_tests(struct obd_device *obd) if (rc) GOTO(cleanup, rc); + rc = llog_test_7(obd); + if (rc) + GOTO(cleanup, rc); + cleanup: switch (cleanup_phase) { case 1: -- 1.8.3.1