From: Andrew Price <anprice@redhat.com>
To: cluster-devel.redhat.com
Subject: [Cluster-devel] [PATCH 3/5] libgfs2: Don't try to read more than IOV_MAX iovecs
Date: Thu, 20 Mar 2014 14:46:44 +0000 [thread overview]
Message-ID: <1395326806-23093-3-git-send-email-anprice@redhat.com> (raw)
In-Reply-To: <1395326806-23093-1-git-send-email-anprice@redhat.com>
Reading large collections of blocks, as gfs2_rgrp_read may do with large
rgrps and small block sizes, can cause preadv() to fail with EINVAL in
breadm(). This patch splits large reads into IOV_MAX chunks to avoid
reads failing in that way. It also includes a test to exercise these
changes.
Signed-off-by: Andrew Price <anprice@redhat.com>
---
gfs2/libgfs2/buf.c | 57 ++++++++++++++++++++++++++++++++----------------------
tests/mkfs.at | 4 ++++
2 files changed, 38 insertions(+), 23 deletions(-)
diff --git a/gfs2/libgfs2/buf.c b/gfs2/libgfs2/buf.c
index 6fcdd17..92cd393 100644
--- a/gfs2/libgfs2/buf.c
+++ b/gfs2/libgfs2/buf.c
@@ -15,6 +15,14 @@
#include "libgfs2.h"
+#ifndef IOV_MAX
+ #ifdef UIO_MAXIOV
+ #define IOV_MAX UIO_MAXIOV
+ #else
+ #define IOV_MAX (1024)
+ #endif
+#endif
+
struct gfs2_buffer_head *bget(struct gfs2_sbd *sdp, uint64_t num)
{
struct gfs2_buffer_head *bh;
@@ -34,31 +42,34 @@ struct gfs2_buffer_head *bget(struct gfs2_sbd *sdp, uint64_t num)
int __breadm(struct gfs2_sbd *sdp, struct gfs2_buffer_head **bhs, size_t n,
uint64_t block, int line, const char *caller)
{
- struct iovec *iov = alloca(n * sizeof(struct iovec));
+ size_t v = (n < IOV_MAX) ? n : IOV_MAX;
+ struct iovec *iov = alloca(v * sizeof(struct iovec));
struct iovec *iovbase = iov;
- uint64_t b = block;
- size_t size = 0;
- size_t i;
- int ret;
-
- for (i = 0; i < n; i++) {
- bhs[i] = bget(sdp, b++);
- if (bhs[i] == NULL)
- return -1;
- *iov++ = bhs[i]->iov;
- size += bhs[i]->iov.iov_len;
+ size_t i = 0;
+
+ while (i < n) {
+ int j;
+ ssize_t ret;
+ ssize_t size = 0;
+
+ for (j = 0; (i + j < n) && (j < IOV_MAX); j++) {
+ bhs[i + j] = bget(sdp, block + i + j);
+ if (bhs[i + j] == NULL)
+ return -1;
+ iov[j] = bhs[i + j]->iov;
+ size += bhs[i + j]->iov.iov_len;
+ }
+
+ ret = preadv(sdp->device_fd, iovbase, j, (block + i) * sdp->bsize);
+ if (ret != size) {
+ fprintf(stderr, "bad read: %s from %s:%d: block %llu (0x%llx) "
+ "count: %d size: %zd ret: %zd\n", strerror(errno),
+ caller, line, (unsigned long long)block,
+ (unsigned long long)block, j, size, ret);
+ exit(-1);
+ }
+ i += j;
}
-
- ret = preadv(sdp->device_fd, iovbase, n, block * sdp->bsize);
-
- if (ret != size) {
- fprintf(stderr, "bad read: %s from %s:%d: block "
- "%llu (0x%llx)\n", strerror(errno),
- caller, line, (unsigned long long)block,
- (unsigned long long)block);
- exit(-1);
- }
-
return 0;
}
diff --git a/tests/mkfs.at b/tests/mkfs.at
index 2616109..ff99bb1 100644
--- a/tests/mkfs.at
+++ b/tests/mkfs.at
@@ -54,6 +54,10 @@ AT_SETUP([Min. resource group size])
GFS_FSCK_CHECK([$GFS_MKFS -p lock_nolock -r 32 $GFS_TGT])
AT_CLEANUP
+AT_SETUP([Max. resource group size, min. block size])
+GFS_FSCK_CHECK([$GFS_MKFS -p lock_nolock -r 2048 -b 512 $GFS_TGT])
+AT_CLEANUP
+
AT_SETUP([Max. journal size])
GFS_FSCK_CHECK([$GFS_MKFS -p lock_nolock -J 1024 $GFS_TGT])
AT_CLEANUP
--
1.8.5.3
next prev parent reply other threads:[~2014-03-20 14:46 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-03-20 14:46 [Cluster-devel] [PATCH 1/5] mkfs.gfs2: Make dev a member of mkfs_opts Andrew Price
2014-03-20 14:46 ` [Cluster-devel] [PATCH 2/5] libgfs2: Add lgfs2_space_for_data() Andrew Price
2014-03-20 14:46 ` Andrew Price [this message]
2014-03-20 14:46 ` [Cluster-devel] [PATCH 4/5] mkfs.gfs2: Fix the resource group layout strategy, again Andrew Price
2014-03-20 14:46 ` [Cluster-devel] [PATCH 5/5] libgfs2: Don't call gfs2_blk2rgrpd in gfs2_set_bitmap Andrew Price
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=1395326806-23093-3-git-send-email-anprice@redhat.com \
--to=anprice@redhat.com \
/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;
as well as URLs for NNTP newsgroup(s).