public inbox for linux-raid@vger.kernel.org
 help / color / mirror / Atom feed
From: Mateusz Grzonka <mateusz.grzonka@intel.com>
To: linux-raid@vger.kernel.org
Cc: jes@trained-monkey.org
Subject: [PATCH] Incremental: Close unclosed mdfd in IncrementalScan()
Date: Wed, 24 Nov 2021 11:45:30 +0100	[thread overview]
Message-ID: <20211124104530.26592-1-mateusz.grzonka@intel.com> (raw)

In addition to closing mdfd, propagate helpers to manage file
descriptors across IncrementalScan().

Signed-off-by: Mateusz Grzonka <mateusz.grzonka@intel.com>
---
 Incremental.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/Incremental.c b/Incremental.c
index cd9cc0fc..9cdd31f0 100644
--- a/Incremental.c
+++ b/Incremental.c
@@ -1346,7 +1346,7 @@ restart:
 		}
 		mdfd = open_dev(me->devnm);
 
-		if (mdfd < 0)
+		if (!is_fd_valid(mdfd))
 			continue;
 		if (!isdigit(me->metadata[0])) {
 			/* must be a container */
@@ -1356,7 +1356,7 @@ restart:
 
 			if (st && st->ss->load_container)
 				ret = st->ss->load_container(st, mdfd, NULL);
-			close(mdfd);
+			close_fd(&mdfd);
 			if (!ret && st && st->ss->container_content) {
 				if (map_lock(&map))
 					pr_err("failed to get exclusive lock on mapfile\n");
@@ -1368,7 +1368,7 @@ restart:
 			continue;
 		}
 		if (md_array_active(mdfd)) {
-			close(mdfd);
+			close_fd(&mdfd);
 			continue;
 		}
 		/* Ok, we can try this one.   Maybe it needs a bitmap */
@@ -1385,9 +1385,9 @@ restart:
 			int bmfd;
 
 			bmfd = open(mddev->bitmap_file, O_RDWR);
-			if (bmfd >= 0) {
+			if (is_fd_valid(bmfd)) {
 				added = ioctl(mdfd, SET_BITMAP_FILE, bmfd);
-				close(bmfd);
+				close_fd(&bmfd);
 			}
 			if (c->verbose >= 0) {
 				if (added == 0)
@@ -1416,6 +1416,7 @@ restart:
 			}
 			sysfs_free(sra);
 		}
+		close_fd(&mdfd);
 	}
 	map_free(mapl);
 	return rv;
-- 
2.26.2


             reply	other threads:[~2021-11-24 10:57 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-24 10:45 Mateusz Grzonka [this message]
2021-11-24 12:06 ` [PATCH] Incremental: Close unclosed mdfd in IncrementalScan() Jes Sorensen

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=20211124104530.26592-1-mateusz.grzonka@intel.com \
    --to=mateusz.grzonka@intel.com \
    --cc=jes@trained-monkey.org \
    --cc=linux-raid@vger.kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox