From 3368e8a436cfd36932955de4505709c79d87f0bb Mon Sep 17 00:00:00 2001 From: zhanghc Date: Mon, 24 Aug 2009 05:43:52 +0000 Subject: [PATCH] b=19791 obdclass/llog_lvfs.c: llog_lvfs_create l_dentry_open will call dput if there is an error, then there should be no similar call(l_dput) if error returned i=adilger@sun.com i=alexey.lyashkov@sun.com --- lustre/lvfs/lvfs_linux.c | 1 + lustre/obdclass/llog_lvfs.c | 36 ++++++++++++++++-------------------- 2 files changed, 17 insertions(+), 20 deletions(-) diff --git a/lustre/lvfs/lvfs_linux.c b/lustre/lvfs/lvfs_linux.c index bb7be27..a189007 100644 --- a/lustre/lvfs/lvfs_linux.c +++ b/lustre/lvfs/lvfs_linux.c @@ -432,6 +432,7 @@ int lustre_fsync(struct file *file) } EXPORT_SYMBOL(lustre_fsync); +/* Note: dput(dchild) will be called if there is an error */ struct l_file *l_dentry_open(struct lvfs_run_ctxt *ctxt, struct l_dentry *de, int flags) { diff --git a/lustre/obdclass/llog_lvfs.c b/lustre/obdclass/llog_lvfs.c index 05b5066..d7f2c08 100644 --- a/lustre/obdclass/llog_lvfs.c +++ b/lustre/obdclass/llog_lvfs.c @@ -589,7 +589,7 @@ static int llog_lvfs_create(struct llog_ctxt *ctxt, struct llog_handle **res, struct obd_device *obd; struct l_dentry *dchild = NULL; struct obdo *oa = NULL; - int rc = 0, cleanup_phase = 1; + int rc = 0; int open_flags = O_RDWR | O_CREAT | O_LARGEFILE; ENTRY; @@ -610,24 +610,25 @@ static int llog_lvfs_create(struct llog_ctxt *ctxt, struct llog_handle **res, rc = PTR_ERR(dchild); CERROR("error looking up logfile "LPX64":0x%x: rc %d\n", logid->lgl_oid, logid->lgl_ogen, rc); - GOTO(cleanup, rc); + GOTO(out, rc); } - cleanup_phase = 2; if (dchild->d_inode == NULL) { + l_dput(dchild); rc = -ENOENT; CERROR("nonexistent log file "LPX64":"LPX64": rc %d\n", logid->lgl_oid, logid->lgl_ogr, rc); - GOTO(cleanup, rc); + GOTO(out, rc); } + /* l_dentry_open will call dput(dchild) if there is an error */ handle->lgh_file = l_dentry_open(&obd->obd_lvfs_ctxt, dchild, O_RDWR | O_LARGEFILE); if (IS_ERR(handle->lgh_file)) { rc = PTR_ERR(handle->lgh_file); CERROR("error opening logfile "LPX64"0x%x: rc %d\n", logid->lgl_oid, logid->lgl_ogen, rc); - GOTO(cleanup, rc); + GOTO(out, rc); } /* assign the value of lgh_id for handle directly */ @@ -645,7 +646,7 @@ static int llog_lvfs_create(struct llog_ctxt *ctxt, struct llog_handle **res, 0644); } if (IS_ERR(handle->lgh_file)) - GOTO(cleanup, rc = PTR_ERR(handle->lgh_file)); + GOTO(out, rc = PTR_ERR(handle->lgh_file)); handle->lgh_id.lgl_ogr = 1; handle->lgh_id.lgl_oid = @@ -655,25 +656,25 @@ static int llog_lvfs_create(struct llog_ctxt *ctxt, struct llog_handle **res, } else { OBDO_ALLOC(oa); if (oa == NULL) - GOTO(cleanup, rc = -ENOMEM); + GOTO(out, rc = -ENOMEM); oa->o_gr = FILTER_GROUP_LLOG; oa->o_valid = OBD_MD_FLGENER | OBD_MD_FLGROUP; rc = obd_create(ctxt->loc_exp, oa, NULL, NULL); if (rc) - GOTO(cleanup, rc); + GOTO(out, rc); dchild = obd_lvfs_fid2dentry(ctxt->loc_exp, oa->o_id, oa->o_generation, oa->o_gr); if (IS_ERR(dchild)) - GOTO(cleanup, rc = PTR_ERR(dchild)); - cleanup_phase = 2; + GOTO(out, rc = PTR_ERR(dchild)); + handle->lgh_file = l_dentry_open(&obd->obd_lvfs_ctxt, dchild, open_flags); if (IS_ERR(handle->lgh_file)) - GOTO(cleanup, rc = PTR_ERR(handle->lgh_file)); + GOTO(out, rc = PTR_ERR(handle->lgh_file)); handle->lgh_id.lgl_ogr = oa->o_gr; handle->lgh_id.lgl_oid = oa->o_id; @@ -681,18 +682,13 @@ static int llog_lvfs_create(struct llog_ctxt *ctxt, struct llog_handle **res, } handle->lgh_ctxt = ctxt; - finish: + out: + if (rc) + llog_free_handle(handle); + if (oa) OBDO_FREE(oa); RETURN(rc); -cleanup: - switch (cleanup_phase) { - case 2: - l_dput(dchild); - case 1: - llog_free_handle(handle); - } - goto finish; } static int llog_lvfs_close(struct llog_handle *handle) -- 1.8.3.1