All of lore.kernel.org
 help / color / mirror / Atom feed
From: James Simmons <jsimmons@infradead.org>
To: lustre-devel@lists.lustre.org
Subject: [lustre-devel] [PATCH 09/28] lustre: lov: reduce code indentation
Date: Mon, 17 Dec 2018 11:29:43 -0500	[thread overview]
Message-ID: <1545064202-22483-10-git-send-email-jsimmons@infradead.org> (raw)
In-Reply-To: <1545064202-22483-1-git-send-email-jsimmons@infradead.org>

From: Bobi Jam <bobijam@hotmail.com>

For lov_init_raid0() we check for the failure of lo_sub and return
an error rigth away. This allows us to reduce the code indentation.
The same can be done for lov_attr_get_raid0() with the test of
r0->lo_attr_valid.

Signed-off-by: Jinshan Xiong <jinshan.xiong@gmail.com>
Signed-off-by: Bobi Jam <bobijam@hotmail.com>
Signed-off-by: Niu Yawei <yawei.niu@intel.com>
WC-bug-id: https://jira.whamcloud.com/browse/LU-8998
Reviewed-on: https://review.whamcloud.com/24850
Reviewed-by: Lai Siyao <lai.siyao@whamcloud.com>
Signed-off-by: James Simmons <jsimmons@infradead.org>
---
 drivers/staging/lustre/lustre/lov/lov_io.c     |  11 +-
 drivers/staging/lustre/lustre/lov/lov_object.c | 186 ++++++++++++-------------
 2 files changed, 96 insertions(+), 101 deletions(-)

diff --git a/drivers/staging/lustre/lustre/lov/lov_io.c b/drivers/staging/lustre/lustre/lov/lov_io.c
index 023b588..6dd5639 100644
--- a/drivers/staging/lustre/lustre/lov/lov_io.c
+++ b/drivers/staging/lustre/lustre/lov/lov_io.c
@@ -948,12 +948,13 @@ int lov_io_init_composite(const struct lu_env *env, struct cl_object *obj,
 
 	INIT_LIST_HEAD(&lio->lis_active);
 	io->ci_result = lov_io_slice_init(lio, lov, io);
+	if (io->ci_result)
+		return io->ci_result;
+
+	io->ci_result = lov_io_subio_init(env, lio, io);
 	if (io->ci_result == 0) {
-		io->ci_result = lov_io_subio_init(env, lio, io);
-		if (io->ci_result == 0) {
-			cl_io_slice_add(io, &lio->lis_cl, obj, &lov_io_ops);
-			atomic_inc(&lov->lo_active_ios);
-		}
+		cl_io_slice_add(io, &lio->lis_cl, obj, &lov_io_ops);
+		atomic_inc(&lov->lo_active_ios);
 	}
 	return io->ci_result;
 }
diff --git a/drivers/staging/lustre/lustre/lov/lov_object.c b/drivers/staging/lustre/lustre/lov/lov_object.c
index f5c6da1..1ebaa23 100644
--- a/drivers/staging/lustre/lustre/lov/lov_object.c
+++ b/drivers/staging/lustre/lustre/lov/lov_object.c
@@ -228,6 +228,7 @@ static int lov_init_raid0(const struct lu_env *env, struct lov_device *dev,
 	struct lov_thread_info  *lti     = lov_env_info(env);
 	struct cl_object_conf   *subconf = &lti->lti_stripe_conf;
 	struct lu_fid	   *ofid    = &lti->lti_fid;
+	int psz;
 
 	if (lsm->lsm_magic != LOV_MAGIC_V1 && lsm->lsm_magic != LOV_MAGIC_V3) {
 		dump_lsm(D_ERROR, lsm);
@@ -238,73 +239,76 @@ static int lov_init_raid0(const struct lu_env *env, struct lov_device *dev,
 	LASSERT(!lov->lo_lsm);
 	lov->lo_lsm = lsm_addref(lsm);
 	lov->lo_layout_invalid = true;
+
+	spin_lock_init(&r0->lo_sub_lock);
 	r0->lo_nr  = lsm->lsm_entries[0]->lsme_stripe_count;
 	LASSERT(r0->lo_nr <= lov_targets_nr(dev));
 
 	r0->lo_sub = kvzalloc(r0->lo_nr * sizeof(r0->lo_sub[0]),
 				     GFP_NOFS);
-	if (r0->lo_sub) {
-		int psz = 0;
+	if (!r0->lo_sub)
+		return -ENOMEM;
 
-		result = 0;
-		subconf->coc_inode = conf->coc_inode;
-		spin_lock_init(&r0->lo_sub_lock);
-		/*
-		 * Create stripe cl_objects.
+	psz = 0;
+	result = 0;
+	subconf->coc_inode = conf->coc_inode;
+	/*
+	 * Create stripe cl_objects.
+	 */
+	for (i = 0; i < r0->lo_nr; ++i) {
+		struct cl_device *subdev;
+		struct lov_oinfo *oinfo;
+		int ost_idx;
+
+		oinfo = lsm->lsm_entries[0]->lsme_oinfo[i];
+		if (lov_oinfo_is_dummy(oinfo))
+			continue;
+
+		result = ostid_to_fid(ofid, &oinfo->loi_oi,
+				      oinfo->loi_ost_idx);
+		if (result != 0)
+			goto out;
+
+		ost_idx = oinfo->loi_ost_idx;
+		if (!dev->ld_target[ost_idx]) {
+			CERROR("%s: OST %04x is not initialized\n",
+			       lov2obd(dev->ld_lov)->obd_name, ost_idx);
+			result = -EIO;
+			goto out;
+		}
+
+		subdev = lovsub2cl_dev(dev->ld_target[ost_idx]);
+		subconf->u.coc_oinfo = oinfo;
+		LASSERTF(subdev, "not init ost %d\n", ost_idx);
+		/* In the function below, .hs_keycmp resolves to
+		 * lu_obj_hop_keycmp()
 		 */
-		for (i = 0; i < r0->lo_nr && result == 0; ++i) {
-			struct cl_device *subdev;
-			struct lov_oinfo *oinfo;
-			int ost_idx;
-
-			oinfo = lsm->lsm_entries[0]->lsme_oinfo[i];
-			if (lov_oinfo_is_dummy(oinfo))
-				continue;
-
-			result = ostid_to_fid(ofid, &oinfo->loi_oi,
-					      oinfo->loi_ost_idx);
-			if (result != 0)
-				goto out;
-
-			ost_idx = oinfo->loi_ost_idx;
-			if (!dev->ld_target[ost_idx]) {
-				CERROR("%s: OST %04x is not initialized\n",
-				lov2obd(dev->ld_lov)->obd_name, ost_idx);
-				result = -EIO;
-				goto out;
-			}
+		/* coverity[overrun-buffer-val] */
+		stripe = lov_sub_find(env, subdev, ofid, subconf);
+		if (IS_ERR(stripe)) {
+			result = PTR_ERR(stripe);
+			goto out;
+		}
 
-			subdev = lovsub2cl_dev(dev->ld_target[ost_idx]);
-			subconf->u.coc_oinfo = oinfo;
-			LASSERTF(subdev, "not init ost %d\n", ost_idx);
-			/* In the function below, .hs_keycmp resolves to
-			 * lu_obj_hop_keycmp()
-			 */
-			/* coverity[overrun-buffer-val] */
-			stripe = lov_sub_find(env, subdev, ofid, subconf);
-			if (!IS_ERR(stripe)) {
-				result = lov_init_sub(env, lov, stripe, r0, i);
-				if (result == -EAGAIN) { /* try again */
-					--i;
-					result = 0;
-					continue;
-				}
-			} else {
-				result = PTR_ERR(stripe);
-			}
+		result = lov_init_sub(env, lov, stripe, r0, i);
+		if (result == -EAGAIN) { /* try again */
+			--i;
+			result = 0;
+			continue;
+		}
 
-			if (result == 0) {
-				int sz = lov_page_slice_fixup(lov, stripe);
+		if (result == 0) {
+			int sz = lov_page_slice_fixup(lov, stripe);
 
-				LASSERT(ergo(psz > 0, psz == sz));
-				psz = sz;
-			}
+			LASSERT(ergo(psz > 0, psz == sz));
+			psz = sz;
 		}
-		if (result == 0)
-			cl_object_header(&lov->lo_cl)->coh_page_bufsize += psz;
-	} else {
-		result = -ENOMEM;
 	}
+	if (result == 0)
+		cl_object_header(&lov->lo_cl)->coh_page_bufsize += psz;
+	else
+		result = -ENOMEM;
+
 out:
 	return result;
 }
@@ -567,53 +571,43 @@ static int lov_attr_get_empty(const struct lu_env *env, struct cl_object *obj,
 static int lov_attr_get_raid0(const struct lu_env *env, struct lov_object *lov,
 			      struct cl_attr *attr, struct lov_layout_raid0 *r0)
 {
+	struct lov_stripe_md *lsm = lov->lo_lsm;
+	struct ost_lvb *lvb = &lov_env_info(env)->lti_lvb;
 	int result = 0;
+	u64 kms = 0;
 
-	/* this is called w/o holding type guard mutex, so it must be inside
-	 * an on going IO otherwise lsm may be replaced.
-	 * LU-2117: it turns out there exists one exception. For mmaped files,
-	 * the lock of those files may be requested in the other file's IO
-	 * context, and this function is called in ccc_lock_state(), it will
-	 * hit this assertion.
-	 * Anyway, it's still okay to call attr_get w/o type guard as layout
-	 * can't go if locks exist.
-	 */
-	/* LASSERT(atomic_read(&lsm->lsm_refc) > 1); */
+	if (r0->lo_attr_valid)
+		return 0;
 
-	if (!r0->lo_attr_valid) {
-		struct lov_stripe_md    *lsm = lov->lo_lsm;
-		struct ost_lvb	  *lvb = &lov_env_info(env)->lti_lvb;
-		__u64		    kms = 0;
+	memset(lvb, 0, sizeof(*lvb));
+	/* XXX: timestamps can be negative by sanity:test_39m,
+	 * how can it be?
+	 */
+	lvb->lvb_atime = LLONG_MIN;
+	lvb->lvb_ctime = LLONG_MIN;
+	lvb->lvb_mtime = LLONG_MIN;
 
-		memset(lvb, 0, sizeof(*lvb));
-		/* XXX: timestamps can be negative by sanity:test_39m,
-		 * how can it be?
-		 */
-		lvb->lvb_atime = LLONG_MIN;
-		lvb->lvb_ctime = LLONG_MIN;
-		lvb->lvb_mtime = LLONG_MIN;
+	/*
+	 * XXX that should be replaced with a loop over sub-objects,
+	 * doing cl_object_attr_get() on them. But for now, let's
+	 * reuse old lov code.
+	 */
 
-		/*
-		 * XXX that should be replaced with a loop over sub-objects,
-		 * doing cl_object_attr_get() on them. But for now, let's
-		 * reuse old lov code.
-		 */
+	/*
+	 * XXX take lsm spin-lock to keep lov_merge_lvb_kms()
+	 * happy. It's not needed, because new code uses
+	 * ->coh_attr_guard spin-lock to protect consistency of
+	 * sub-object attributes.
+	 */
+	lov_stripe_lock(lsm);
+	result = lov_merge_lvb_kms(lsm, lvb, &kms);
+	lov_stripe_unlock(lsm);
+	if (result)
+		return result;
 
-		/*
-		 * XXX take lsm spin-lock to keep lov_merge_lvb_kms()
-		 * happy. It's not needed, because new code uses
-		 * ->coh_attr_guard spin-lock to protect consistency of
-		 * sub-object attributes.
-		 */
-		lov_stripe_lock(lsm);
-		result = lov_merge_lvb_kms(lsm, lvb, &kms);
-		lov_stripe_unlock(lsm);
-		if (result == 0) {
-			cl_lvb2attr(attr, lvb);
-			attr->cat_kms = kms;
-			r0->lo_attr_valid = 1;
-		}
-	}
+	cl_lvb2attr(attr, lvb);
+	attr->cat_kms = kms;
+	r0->lo_attr_valid = 1;
 
 	return result;
 }
-- 
1.8.3.1

  parent reply	other threads:[~2018-12-17 16:29 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-17 16:29 [lustre-devel] [PATCH RFC 00/28] lustre: PFL port to linux client James Simmons
2018-12-17 16:29 ` [lustre-devel] [PATCH 01/28] lustre: pfl: Basic data structures for composite layout James Simmons
2018-12-17 23:54   ` NeilBrown
2018-12-18  1:47     ` Patrick Farrell
2018-12-27  1:57     ` James Simmons
2018-12-17 16:29 ` [lustre-devel] [PATCH 02/28] lustre: lov: move code for PFL work James Simmons
2018-12-18  0:00   ` NeilBrown
2018-12-27  1:59     ` James Simmons
2018-12-17 16:29 ` [lustre-devel] [PATCH 03/28] lustre: lov: merge lov_mds_md_v3 and lov_mds_md_v1 handling James Simmons
2018-12-18  0:09   ` NeilBrown
2018-12-18  1:49     ` Patrick Farrell
2018-12-27  2:10       ` James Simmons
2018-12-27  2:04     ` James Simmons
2018-12-17 16:29 ` [lustre-devel] [PATCH 04/28] lustre: lov: fold lmm_verify() handling into lmm_unpackmd() James Simmons
2018-12-17 16:29 ` [lustre-devel] [PATCH 05/28] lustre: lov: create struct lov_stripe_md_entry James Simmons
2018-12-17 16:29 ` [lustre-devel] [PATCH 06/28] lustre: lov: add composite layout unpacking James Simmons
2018-12-17 16:29 ` [lustre-devel] [PATCH 07/28] lustre: lov: embedded raid0 in struct lov_layout_composite James Simmons
2018-12-17 16:29 ` [lustre-devel] [PATCH 08/28] lustre: lov: migrate lov raid0 to future PFL component handling James Simmons
2018-12-17 16:29 ` James Simmons [this message]
2018-12-17 16:29 ` [lustre-devel] [PATCH 10/28] lustre: lov: change lo_entries to array James Simmons
2018-12-17 16:29 ` [lustre-devel] [PATCH 11/28] lustre: lov: move around PFL code and cleanups James Simmons
2018-12-17 16:29 ` [lustre-devel] [PATCH 12/28] lustre: lov: remove lsm_stripe_by_[index|offset]_plain James Simmons
2018-12-17 16:29 ` [lustre-devel] [PATCH 13/28] lustre: lov: add looping lsm_entry_count times James Simmons
2018-12-17 16:29 ` [lustre-devel] [PATCH 14/28] lustre: lov: create lov_comp_* wrappers James Simmons
2018-12-17 16:29 ` [lustre-devel] [PATCH 15/28] lustre: clio: client side implementation for PFL James Simmons
2018-12-17 16:29 ` [lustre-devel] [PATCH 16/28] lustre: clio: getstripe support comp layout James Simmons
2018-12-17 16:29 ` [lustre-devel] [PATCH 17/28] lustre: pfl: enhance PFID EA for PFL James Simmons
2018-12-17 16:29 ` [lustre-devel] [PATCH 18/28] lustre: pfl: dynamic layout modification with write/truncate James Simmons
2018-12-17 16:29 ` [lustre-devel] [PATCH 19/28] lustre: pfl: calculate PFL file LOVEA correctly James Simmons
2018-12-17 16:29 ` [lustre-devel] [PATCH 20/28] lustre: lov: keep minimum LOVEA size James Simmons
2018-12-17 16:29 ` [lustre-devel] [PATCH 21/28] lustre: pfl: Read should not trigger layout write intent James Simmons
2018-12-17 16:29 ` [lustre-devel] [PATCH 22/28] lustre: pfl: fix hang with grouplocks James Simmons
2018-12-17 16:29 ` [lustre-devel] [PATCH 23/28] lustre: pfl: fix ost pool op->size handling James Simmons
2018-12-17 16:29 ` [lustre-devel] [PATCH 24/28] lustre: lov: readahead shouldn't exceed component boundary James Simmons
2018-12-17 16:29 ` [lustre-devel] [PATCH 25/28] lustre: uapi: support negative flags James Simmons
2018-12-17 16:30 ` [lustre-devel] [PATCH 26/28] lustre: llite: return v1/v3 layout for legacy app James Simmons
2018-12-17 16:30 ` [lustre-devel] [PATCH 27/28] lustre: llite: restore ll_file_getstripe in ll_lov_setstripe James Simmons
2018-12-17 16:30 ` [lustre-devel] [PATCH 28/28] lustre: lov: do not split IO for single striped file James Simmons
2018-12-18  6:21 ` [lustre-devel] [PATCH RFC 00/28] lustre: PFL port to linux client NeilBrown
2018-12-20  1:39   ` NeilBrown
2018-12-27  1:53     ` James Simmons

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1545064202-22483-10-git-send-email-jsimmons@infradead.org \
    --to=jsimmons@infradead.org \
    --cc=lustre-devel@lists.lustre.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.