Skip to contentSkip to conversation

drbdmeta: Fix drbdmeta to support old kernels

PATCH In review Artem Pogartsev 2 participants 2 messages Aug 17, 2017 DRBD driver

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drbdmeta: Fix drbdmeta to support old kernels

Hello,

RedHat 6.9
kernel-2.6.32-431.11.2
drbd-utils-9.0.0
drbd-8.4.10

Problem:

drbdmeta 0 v08 /dev/sda internal create-md
initializing activity log
initializing bitmap (30524 KB) to all zero
ioctl(/dev/sda) failed: Invalid argument

Reason:

Wrong check of the return error code into zeroout_bitmap function (user/shared/drbdmeta.c):

err = ioctl(cfg->md_fd, BLKZEROOUT, &range);
if (!err)

        return;
if (errno == ENOTTY) {
        do pwrite stuff;
}

We must check if errno == EINVAL (request code or argp is not valid). We will get ENOTTY if the block device doesnt has ioctl into fops structure (look at the __blkdev_driver_ioctl into block/ioctl.c) - not out case. And we will get EINVAL if the request code is wrong for this type of the device (old kernels doesnt have BLKZEROOUT) - our case.

Possible patch is attached.

But maybe better change logic and make ioctl with BLKZEROOUT only if BLKZEROOUT was defined in kernel headers (if we dont have BLKZEROOUT macro in kernel tree then 100% ioctl with _IO(0x12,127) will fail).

user/shared/drbdmeta.c +1 -1
diff -Nru a/user/shared/drbdmeta.c b/user/shared/drbdmeta.c
@@ -1716,7 +1716,7 @@
 	if (!err)
 		return;
 
-	if (errno == ENOTTY) {
+	if (errno == EINVAL) {
 		/* need to sector-align this for O_DIRECT.
 		 * "sector" here means hard-sect size, which may be != 512.
 		 * Note that even though ALIGN does round up, for sector sizes
maintainer
#1 lore raw
Quoted 7 lines · Artem Pogartsev

Hello,

RedHat 6.9
kernel-2.6.32-431.11.2
drbd-utils-9.0.0
drbd-8.4.10

Quoted 6 lines

Problem:

drbdmeta 0 v08 /dev/sda internal create-md
initializing activity log
initializing bitmap (30524 KB) to all zero
ioctl(/dev/sda) failed: Invalid argument

Thanks for pointing this out.

I'm about to commit this instead:

drbdmeta compat: fixup fallback path for BLKZEROOUT for older kernels

Based on a suggestion on drbd-dev by
From: Artem Pogartsev <[email protected]>
Date: Thu, 17 Aug 2017 04:57:12 +0300
To: [email protected]
Subject: [PATCH] drbdmeta: Fix drbdmeta to support old kernels
Message-ID: <[email protected]>

Though I chose to always execute the fallback code if the ioctl BLKZEROOUT fails, regardless of errno.

As a side note,
just because the define BLKZEROOUT is not in the (userland) headers (yet) does not necessarily mean the kernel does not know it.

user/shared/drbdmeta.c +11 -5
index 6ff877a..86f32ed 100644
@@ -60,7 +60,12 @@
 
 #include "config.h"
 
-/* BLKZEROOUT, available on linux-3.6 and later. */
+/* BLKZEROOUT, available on linux-3.6 and later,
+ * and maybe backported to distribution kernels,
+ * even if they pretend to be older.
+ * Yes, we encountered a number of systems that already had it in their
+ * kernels, but not yet in the headers used to build userland stuff like this.
+ */
 #ifndef BLKZEROOUT
 # define BLKZEROOUT	_IO(0x12,127)
 #endif
@@ -1716,7 +1721,11 @@ static void zeroout_bitmap(struct format *cfg)
 	if (!err)
 		return;
 
-	if (errno == ENOTTY) {
+	PERROR("ioctl(%s, BLKZEROOUT, [%llu, %llu]) failed", cfg->md_device_name,
+			(unsigned long long)range[0], (unsigned long long)range[1]);
+	fprintf(stderr, "Using slow(er) fallback.\n");
+
+	{
 		/* need to sector-align this for O_DIRECT.
 		 * "sector" here means hard-sect size, which may be != 512.
 		 * Note that even though ALIGN does round up, for sector sizes
@@ -1744,9 +1753,6 @@ static void zeroout_bitmap(struct format *cfg)
 			}
 		}
 		fprintf(stderr,"\r100%%\n");
-	} else {
-		PERROR("ioctl(%s) failed", cfg->md_device_name);
-		exit(10);
 	}
 }