git » libjio » commit 9519d02

btrfs: Use sysconf(_SC_PAGESIZE) instead of the hardcoded size

author Alberto Bertogli
2009-10-10 19:43:41 UTC
committer Alberto Bertogli
2009-10-10 19:45:19 UTC
parent bbfa7b7d288ae0cef484753c7c9673923433fada

btrfs: Use sysconf(_SC_PAGESIZE) instead of the hardcoded size

According to 20090929165122.GB2650@think (""Re: Clone range ioctl", 29 Sep
2009) we should use the page size to align offsets for btrfs.

Signed-off-by: Alberto Bertogli <albertito@blitiri.com.ar>

libjio/journal.c +7 -1
libjio/journal.h +2 -1

diff --git a/libjio/journal.c b/libjio/journal.c
index e2a4889..28ab8f3 100644
--- a/libjio/journal.c
+++ b/libjio/journal.c
@@ -331,7 +331,6 @@ error:
 }
 
 
-static unsigned char empty_blk[BSZ];
 
 /** Save a single operation in the journal file */
 int journal_add_op(struct journal_op *jop, unsigned char *buf, size_t len,
@@ -340,6 +339,13 @@ int journal_add_op(struct journal_op *jop, unsigned char *buf, size_t len,
 	ssize_t rv;
 	struct on_disk_ophdr ophdr;
 	struct iovec iov[3];
+	static unsigned char *empty_blk = NULL;
+
+	if (empty_blk == NULL) {
+		empty_blk = malloc(BSZ);
+		if (empty_blk == NULL)
+			goto error;
+	}
 
 	/* start at 4k boundary */
 	off_t curpos = lseek(jop->fd, 0, SEEK_CUR);
diff --git a/libjio/journal.h b/libjio/journal.h
index 57eff46..98f7d76 100644
--- a/libjio/journal.h
+++ b/libjio/journal.h
@@ -3,10 +3,11 @@
 #define _JOURNAL_H
 
 #include <stdint.h>
+#include <unistd.h>		/* sysconf() */
 #include "libjio.h"
 
 /* filesystem block size */
-#define BSZ 4096
+#define BSZ sysconf(_SC_PAGESIZE)
 
 struct journal_op {
 	int id;