From acabfb9594c956081b615d22cfc1bd39e8a3f331 Mon Sep 17 00:00:00 2001 From: Vladimir Saveliev Date: Thu, 15 Feb 2018 18:40:16 +0300 Subject: [PATCH] LU-5991 obd: fix mount error handing lustre_fill_super() allocates lsi and assumes that on failures lsi will be freed by server_fill_super() or ll_fill_super(). - server_fill_super() does not free lsi when lsi_prepare() fails. - ll_fill_super() does not free lsi when OBD_ALLOC_PTR(cfg) or ll_init_sbi() fail. osd_device_fini() needs osd_index_backup(). Otherwise struct lustre_index_backup_unit-s leak if server_fill_super() fails after osd_start(). Cray-bug-id: MRP-2229 Signed-off-by: Vladimir Saveliev Change-Id: I366dc2b46a504a65b030bcbf687998dd0676f404 Reviewed-by: Sergey Cheremencev Reviewed-by: Andriy Skulysh Reviewed-on: https://review.whamcloud.com/12959 Tested-by: Jenkins Tested-by: Maloo Reviewed-by: Oleg Drokin --- lustre/llite/llite_lib.c | 24 ++++++++++++------------ lustre/obdclass/obd_mount_server.c | 4 +++- lustre/osd-ldiskfs/osd_handler.c | 1 + 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/lustre/llite/llite_lib.c b/lustre/llite/llite_lib.c index acf35e6..0f95175 100644 --- a/lustre/llite/llite_lib.c +++ b/lustre/llite/llite_lib.c @@ -997,7 +997,7 @@ int ll_fill_super(struct super_block *sb, struct vfsmount *mnt) { struct lustre_profile *lprof = NULL; struct lustre_sb_info *lsi = s2lsi(sb); - struct ll_sb_info *sbi; + struct ll_sb_info *sbi = NULL; char *dt = NULL, *md = NULL; char *profilenm = get_profile_name(sb); struct config_llog_instance *cfg; @@ -1010,19 +1010,16 @@ int ll_fill_super(struct super_block *sb, struct vfsmount *mnt) CDEBUG(D_VFSTRACE, "VFS Op: sb %p\n", sb); + try_module_get(THIS_MODULE); + OBD_ALLOC_PTR(cfg); if (cfg == NULL) - RETURN(-ENOMEM); - - try_module_get(THIS_MODULE); + GOTO(out_free, err = -ENOMEM); /* client additional sb info */ lsi->lsi_llsbi = sbi = ll_init_sbi(); - if (!sbi) { - module_put(THIS_MODULE); - OBD_FREE_PTR(cfg); - RETURN(-ENOMEM); - } + if (!sbi) + GOTO(out_free, err = -ENOMEM); err = ll_options(lsi->lsi_lmd->lmd_opts, &sbi->ll_flags); if (err) @@ -1100,12 +1097,12 @@ out_free: OBD_FREE(dt, dt_len); if (lprof != NULL) class_put_profile(lprof); + if (cfg) + OBD_FREE_PTR(cfg); if (err) ll_put_super(sb); else if (sbi->ll_flags & LL_SBI_VERBOSE) LCONSOLE_WARN("Mounted %s\n", profilenm); - - OBD_FREE_PTR(cfg); RETURN(err); } /* ll_fill_super */ @@ -1120,6 +1117,9 @@ void ll_put_super(struct super_block *sb) int next, force = 1, rc = 0; ENTRY; + if (!sbi) + GOTO(out_no_sbi, 0); + CDEBUG(D_VFSTRACE, "VFS Op: sb %p - %s\n", sb, profilenm); cfg.cfg_instance = sb; @@ -1182,7 +1182,7 @@ void ll_put_super(struct super_block *sb) ll_free_sbi(sb); lsi->lsi_llsbi = NULL; - +out_no_sbi: lustre_common_put_super(sb); cl_env_cache_purge(~0); diff --git a/lustre/obdclass/obd_mount_server.c b/lustre/obdclass/obd_mount_server.c index 8441d5b..c65cb53 100644 --- a/lustre/obdclass/obd_mount_server.c +++ b/lustre/obdclass/obd_mount_server.c @@ -1890,8 +1890,10 @@ int server_fill_super(struct super_block *sb) OBD_RACE(OBD_FAIL_TGT_MOUNT_RACE); rc = lsi_prepare(lsi); - if (rc) + if (rc) { + lustre_put_lsi(sb); RETURN(rc); + } /* Start low level OSD */ rc = osd_start(lsi, sb->s_flags); diff --git a/lustre/osd-ldiskfs/osd_handler.c b/lustre/osd-ldiskfs/osd_handler.c index 7bcf863..9519356 100644 --- a/lustre/osd-ldiskfs/osd_handler.c +++ b/lustre/osd-ldiskfs/osd_handler.c @@ -7293,6 +7293,7 @@ static struct lu_device *osd_device_fini(const struct lu_env *env, struct osd_device *o = osd_dev(d); ENTRY; + osd_index_backup(env, o, false); osd_shutdown(env, o); osd_procfs_fini(o); osd_obj_map_fini(o); -- 1.8.3.1