[Ocfs2-tools-devel] [PATCH] return err when ocfs2_get_device_sectsize() can not determine sector size, v2

Coly Li coly.li at suse.de
Tue Mar 10 08:58:06 PDT 2009


This patch is modified from "[PATCH] libocfs2: check sectsize after return from
ocfs2_get_device_sectsize()" with Joel's suggestion.


In ocfs2_get_device_sectsize(), if BLKSSZGET is undefined, *sectsize is set to
0. This is problematic in ocfs2_fill_heartbeat_desc() where sectsize_bits =
ffs(sectsize) - 1; will gets sectsize_bits to be ~0. Though the execution flow
is safe, the logic is not correct.

This patch adds a new error code OCFS2_ET_CANNOT_DETERMINE_SECTOR_SIZE, when
ocfs2_get_device_sectsize() can not determine sector size, just returns this
error code.

Signed-off-by: Coly Li <coly.li at suse.de>
Cc: Joel Becker <Joel.Becker at oracle.com>
Cc: Sunil Mushran <sunil.mushran at oracle.com>
---
 libocfs2/getsectsize.c |   11 +++++------
 libocfs2/ocfs2_err.et  |    3 +++
 2 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/libocfs2/getsectsize.c b/libocfs2/getsectsize.c
index 937baa6..c487733 100644
--- a/libocfs2/getsectsize.c
+++ b/libocfs2/getsectsize.c
@@ -45,6 +45,7 @@
 errcode_t ocfs2_get_device_sectsize(const char *file, int *sectsize)
 {
 	int	fd;
+	int	ret;

 #ifdef HAVE_OPEN64
 	fd = open64(file, O_RDONLY);
@@ -54,15 +55,13 @@ errcode_t ocfs2_get_device_sectsize(const char *file, int
*sectsize)
 	if (fd < 0)
 		return errno;

+	ret = OCFS2_ET_CANNOT_DETERMINE_SECTOR_SIZE;
 #ifdef BLKSSZGET
-	if (ioctl(fd, BLKSSZGET, sectsize) >= 0) {
-		close(fd);
-		return 0;
-	}
+	if (ioctl(fd, BLKSSZGET, sectsize) >= 0)
+		ret = 0;
 #endif
-	*sectsize = 0;
 	close(fd);
-	return 0;
+	return ret;
 }

 #ifdef DEBUG_EXE
diff --git a/libocfs2/ocfs2_err.et b/libocfs2/ocfs2_err.et
index b169ec7..13ea933 100644
--- a/libocfs2/ocfs2_err.et
+++ b/libocfs2/ocfs2_err.et
@@ -181,4 +181,7 @@ ec	OCFS2_ET_UNKNOWN_FEATURE,
 ec	OCFS2_ET_BAD_DIR_BLOCK_MAGIC,
 	"Bad magic number in directory block"

+ec	OCFS2_ET_CANNOT_DETERMINE_SECTOR_SIZE,
+	"Cannot determine sector size"
+
 	end
-- 
Coly Li
SuSE Labs






More information about the Ocfs2-tools-devel mailing list