All of lore.kernel.org
 help / color / mirror / Atom feed
* [Cluster-devel] libgfs2: Add iovec to gfs2_buffer_head
@ 2011-12-16 14:24 Steven Whitehouse
  2011-12-16 20:25 ` Andrew Price
  0 siblings, 1 reply; 2+ messages in thread
From: Steven Whitehouse @ 2011-12-16 14:24 UTC (permalink / raw)
  To: cluster-devel.redhat.com


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>

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;
 };
 




^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [Cluster-devel] libgfs2: Add iovec to gfs2_buffer_head
  2011-12-16 14:24 [Cluster-devel] libgfs2: Add iovec to gfs2_buffer_head Steven Whitehouse
@ 2011-12-16 20:25 ` Andrew Price
  0 siblings, 0 replies; 2+ messages in thread
From: Andrew Price @ 2011-12-16 20:25 UTC (permalink / raw)
  To: cluster-devel.redhat.com

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;
>   };
>
>
>



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2011-12-16 20:25 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-12-16 14:24 [Cluster-devel] libgfs2: Add iovec to gfs2_buffer_head Steven Whitehouse
2011-12-16 20:25 ` Andrew Price

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.