[stgt] [PATCH 07/15] tgt: os.h: sync_file_range is OS dependent
Boaz Harrosh
bharrosh at panasas.com
Sun Mar 1 17:50:42 CET 2009
Introduce a new header that includes definitions of all
OS specific services. stgt code will use abstract API from
os.h. (start with os_xxx). Then a linux/os.c and bsd/os.c
implement these services for the needed platform.
First such service is sync_file_range which needs to be
emulated in bsd.
Signed-off-by: Boaz Harrosh <bharrosh at panasas.com>
---
usr/Makefile | 3 +++
usr/bs_mmap.c | 2 +-
usr/bs_rdwr.c | 2 +-
usr/bsd/os.c | 24 ++++++++++++++++++++++++
usr/linux/os.c | 45 +++++++++++++++++++++++++++++++++++++++++++++
usr/os.h | 13 +++++++++++++
usr/util.h | 38 +-------------------------------------
7 files changed, 88 insertions(+), 39 deletions(-)
create mode 100644 usr/bsd/os.c
create mode 100644 usr/linux/os.c
create mode 100644 usr/os.h
diff --git a/usr/Makefile b/usr/Makefile
index 3fc848e..03b3c90 100644
--- a/usr/Makefile
+++ b/usr/Makefile
@@ -65,6 +65,9 @@ TGTD_OBJS += tgtd.o mgmt.o target.o scsi.o log.o driver.o util.o work.o \
parser.o spc.o sbc.o mmc.o osd.o scc.o smc.o \
ssc.o bs_ssc.o libssc.o \
bs_null.o bs_sg.o bs.o libcrc32c.o
+
+TGTD_OBJS += linux/os.o
+
MANPAGES = ../doc/manpages/tgtadm.8 ../doc/manpages/tgt-admin.8 \
../doc/manpages/tgt-setup-lun.8
DOCS = ../doc/README.fcoe ../doc/README.ibmvstgt ../doc/README.iscsi ../doc/README.iser \
diff --git a/usr/bs_mmap.c b/usr/bs_mmap.c
index bb24f5e..8eb6a47 100644
--- a/usr/bs_mmap.c
+++ b/usr/bs_mmap.c
@@ -60,7 +60,7 @@ static void bs_mmap_request(struct scsi_cmd *cmd)
unsigned int flags =
SYNC_FILE_RANGE_WAIT_BEFORE| SYNC_FILE_RANGE_WRITE;
- ret = __sync_file_range(cmd->dev->fd, cmd->offset, length, flags);
+ ret = os_sync_file_range(cmd->dev->fd, cmd->offset, length, flags);
if (ret) {
result = SAM_STAT_CHECK_CONDITION;
key = MEDIUM_ERROR;
diff --git a/usr/bs_rdwr.c b/usr/bs_rdwr.c
index 65a6136..0c21e01 100644
--- a/usr/bs_rdwr.c
+++ b/usr/bs_rdwr.c
@@ -51,7 +51,7 @@ static void bs_sync_sync_range(struct scsi_cmd *cmd, uint32_t length,
int ret;
unsigned int flags = SYNC_FILE_RANGE_WAIT_BEFORE| SYNC_FILE_RANGE_WRITE;
- ret = __sync_file_range(cmd->dev->fd, cmd->offset, length, flags);
+ ret = os_sync_file_range(cmd->dev->fd, cmd->offset, length, flags);
if (ret)
set_medium_error(result, key, asc);
}
diff --git a/usr/bsd/os.c b/usr/bsd/os.c
new file mode 100644
index 0000000..f24f515
--- /dev/null
+++ b/usr/bsd/os.c
@@ -0,0 +1,24 @@
+/*
+* os.c: OS dependent services implementation on BSD platform
+*
+* Description:
+* Implements these services in os.h on the BSD platform
+*
+* Author: Boaz Harrosh <bharrosh at panasas.com>, (C) 2009
+*
+* Copyright: See COPYING file that comes with this distribution
+*
+*/
+
+#include <errno.h>
+#include <unistd.h>
+
+#include <linux/fs.h>
+
+#include "os.h"
+
+int os_sync_file_range(int fd, __off64_t offset, __off64_t bytes,
+ unsigned int flags)
+{
+ return fsync(fd);
+}
diff --git a/usr/linux/os.c b/usr/linux/os.c
new file mode 100644
index 0000000..77bd074
--- /dev/null
+++ b/usr/linux/os.c
@@ -0,0 +1,45 @@
+/*
+* os.c: OS dependent services implementation on Linux platform
+*
+* Description:
+*
+*
+* Author: Boaz Harrosh <bharrosh at panasas.com>, (C) 2009
+*
+* Copyright: See COPYING file that comes with this distribution
+*
+*/
+
+#include <errno.h>
+#include <unistd.h>
+#include <sys/syscall.h>
+
+#include "os.h"
+
+/*
+ * the latest glibc have a proper sync_file_range definition but
+ * most of the distributions aren't shipped with it yet.
+*/
+#ifndef __NR_sync_file_range
+#if defined(__i386)
+#define __NR_sync_file_range 314
+#elif defined(__x86_64__)
+#define __NR_sync_file_range 277
+#elif defined(__ia64__)
+#define __NR_sync_file_range 1300
+#elif defined(__powerpc64__) || defined(__PPC__)
+#define __NR_sync_file_range 308
+#endif
+#endif
+
+int os_sync_file_range(int fd, __off64_t offset, __off64_t bytes,
+ unsigned int flags)
+{
+ int ret;
+
+ ret = syscall(__NR_sync_file_range, fd, offset, bytes, flags);
+ if (ret == -EPERM)
+ ret = fsync(fd);
+ return ret;
+}
+
diff --git a/usr/os.h b/usr/os.h
new file mode 100644
index 0000000..cd4dd71
--- /dev/null
+++ b/usr/os.h
@@ -0,0 +1,13 @@
+#ifndef __TGT_OS_H__
+#define __TGT_OS_H__
+
+#ifndef SYNC_FILE_RANGE_WAIT_BEFORE
+#define SYNC_FILE_RANGE_WAIT_BEFORE 1
+#define SYNC_FILE_RANGE_WRITE 2
+#define SYNC_FILE_RANGE_WAIT_AFTER 4
+#endif
+int os_sync_file_range(int fd, __off64_t offset, __off64_t bytes,
+ unsigned int flags);
+
+
+#endif /* ndef __TGT_OS_H__*/
diff --git a/usr/util.h b/usr/util.h
index 419f648..18e0eb0 100644
--- a/usr/util.h
+++ b/usr/util.h
@@ -7,6 +7,7 @@
#include <errno.h>
#include <endian.h>
#include "be_byteshift.h"
+#include "os.h"
#define roundup(x, y) ((((x) + ((y) - 1)) / (y)) * (y))
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
@@ -101,41 +102,4 @@ do { \
extern unsigned long pagesize, pageshift;
-
-/*
- * the latest glibc have a proper sync_file_range definition but
- * most of the distributions aren't shipped with it yet.
-*/
-
-#ifndef __NR_sync_file_range
-#if defined(__i386)
-#define __NR_sync_file_range 314
-#elif defined(__x86_64__)
-#define __NR_sync_file_range 277
-#elif defined(__ia64__)
-#define __NR_sync_file_range 1300
-#elif defined(__powerpc64__) || defined(__PPC__)
-#define __NR_sync_file_range 308
-#endif
-#endif
-
-#ifndef SYNC_FILE_RANGE_WAIT_BEFORE
-#define SYNC_FILE_RANGE_WAIT_BEFORE 1
-#define SYNC_FILE_RANGE_WRITE 2
-#define SYNC_FILE_RANGE_WAIT_AFTER 4
-#endif
-
-extern long int syscall(long int sysno, ...);
-
-static inline int __sync_file_range(int fd, __off64_t offset, __off64_t bytes,
- unsigned int flags)
-{
- int ret;
-
- ret = syscall(__NR_sync_file_range, fd, offset, bytes, flags);
- if (ret == -EPERM)
- ret = fsync(fd);
- return ret;
-}
-
#endif
--
1.6.0.6
--
To unsubscribe from this list: send the line "unsubscribe stgt" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
More information about the stgt
mailing list