Skip to contentSkip to conversation

libgfs2: Add iovec to gfs2_buffer_head

Cluster-devel Steven Whitehouse 2 participants 2 messages Dec 16, 2011

lore
Share & tools
lore
#0 lore raw

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.

gfs2/libgfs2/buf.c +5 -3
index 445b0ba..956dd8b 100644
@@ -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;
gfs2/libgfs2/libgfs2.h +5 -1
index 0e521fb..d5cac5a 100644
@@ -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;
 };
 
#1 lore raw

Hi,

Quoted 6 lines · Steven Whitehouse

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.

Looks good to me,

Andy

Quoted 60 lines
gfs2/libgfs2/buf.c +5 -3
index 445b0ba..956dd8b 100644
@@ -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;
gfs2/libgfs2/libgfs2.h +5 -1
index 0e521fb..d5cac5a 100644
@@ -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;
  };