[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [Cluster-devel] libgfs2: Add iovec to gfs2_buffer_head



Hi,

On 16/12/11 14:24, Steven Whitehouse wrote:

So that we keep track of buffer sizes, add an iovec to the
gfs2_buffer_head structure. This uses an unnamed union in
order to be backwards compatible with users of b_data.

Signed-off-by: Steven Whitehouse<swhiteho redhat com>

Looks good to me,

Andy


diff --git a/gfs2/libgfs2/buf.c b/gfs2/libgfs2/buf.c
index 445b0ba..956dd8b 100644
--- a/gfs2/libgfs2/buf.c
+++ b/gfs2/libgfs2/buf.c
@@ -24,7 +24,9 @@ struct gfs2_buffer_head *bget(struct gfs2_sbd *sdp, uint64_t num)

  	bh->b_blocknr = num;
  	bh->sdp = sdp;
-	bh->b_data = (char *)bh + sizeof(struct gfs2_buffer_head);
+	bh->iov.iov_base = (char *)bh + sizeof(struct gfs2_buffer_head);
+	bh->iov.iov_len = sdp->bsize;
+
  	return bh;
  }

@@ -42,7 +44,7 @@ struct gfs2_buffer_head *__bread(struct gfs2_sbd *sdp, uint64_t num, int line,
  			(unsigned long long)num);
  		exit(-1);
  	}
-	if (read(sdp->device_fd, bh->b_data, sdp->bsize)<  0) {
+	if (readv(sdp->device_fd,&bh->iov, 1)<  0) {
  		fprintf(stderr, "bad read: %s from %s:%d: block "
  			"%llu (0x%llx)\n", strerror(errno),
  			caller, line, (unsigned long long)num,
@@ -60,7 +62,7 @@ int bwrite(struct gfs2_buffer_head *bh)
  	    bh->b_blocknr * sdp->bsize) {
  		return -1;
  	}
-	if (write(sdp->device_fd, bh->b_data, sdp->bsize) != sdp->bsize)
+	if (writev(sdp->device_fd,&bh->iov, 1) != bh->iov.iov_len)
  		return -1;
  	sdp->writes++;
  	bh->b_modified = 0;
diff --git a/gfs2/libgfs2/libgfs2.h b/gfs2/libgfs2/libgfs2.h
index 0e521fb..d5cac5a 100644
--- a/gfs2/libgfs2/libgfs2.h
+++ b/gfs2/libgfs2/libgfs2.h
@@ -7,6 +7,7 @@
  #include<errno.h>
  #include<sys/types.h>
  #include<sys/stat.h>
+#include<sys/uio.h>
  #include<linux/types.h>
  #include<linux/limits.h>
  #include<endian.h>
@@ -111,7 +112,10 @@ struct gfs2_buffer_head {
  	osi_list_t b_altlist; /* alternate list */
  	uint64_t b_blocknr;
  	int b_modified;
-	char *b_data;
+	union {
+		char *b_data;
+		struct iovec iov;
+	};
  	struct gfs2_sbd *sdp;
  };





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]