[stgt] [PATCH 08/15] tgt: os.h: Services unavailable in BSD

Boaz Harrosh bharrosh at panasas.com
Sun Mar 1 17:51:20 CET 2009


* ipc_perm => os_ipc_perm
	Let in any request. credential checks are turned
	off in BSD.

* oom_adjust - => os_oom_adjust Not available on BSD

* ioctl(, BLKGETSIZE64) => os_blockdev_size
	FIXME: How to do on BSD

Signed-off-by: Boaz Harrosh <bharrosh at panasas.com>
---
 usr/bsd/os.c   |   17 +++++++++++++++++
 usr/linux/os.c |   52 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 usr/mgmt.c     |   27 +--------------------------
 usr/os.h       |    5 +++++
 usr/tgtd.c     |   23 +----------------------
 usr/util.c     |    2 +-
 6 files changed, 77 insertions(+), 49 deletions(-)

diff --git a/usr/bsd/os.c b/usr/bsd/os.c
index f24f515..28a5926 100644
--- a/usr/bsd/os.c
+++ b/usr/bsd/os.c
@@ -22,3 +22,20 @@ int os_sync_file_range(int fd, __off64_t offset, __off64_t bytes,
 {
 	return fsync(fd);
 }
+
+int os_ipc_perm(int fd)
+{
+	return 0;
+}
+
+int os_oom_adjust(void)
+{
+	return 0;
+}
+
+int os_blockdev_size(int fd, uint64_t *size)
+{
+	/* FIXME: how to get block-dev size in BSD */
+	*size = ~0ULL;
+	return 0;
+}
diff --git a/usr/linux/os.c b/usr/linux/os.c
index 77bd074..aeb7b21 100644
--- a/usr/linux/os.c
+++ b/usr/linux/os.c
@@ -11,10 +11,18 @@
 */
 
 #include <errno.h>
+#include <stdio.h>
+#include <inttypes.h>
 #include <unistd.h>
+#include <fcntl.h>
+#include <sys/ioctl.h>
+#include <sys/socket.h>
 #include <sys/syscall.h>
 
+#include <linux/fs.h>
+
 #include "os.h"
+#include "log.h"
 
 /*
  * the latest glibc have a proper sync_file_range definition but
@@ -43,3 +51,47 @@ int os_sync_file_range(int fd, __off64_t offset, __off64_t bytes,
 	return ret;
 }
 
+int os_ipc_perm(int fd)
+{
+	struct ucred cred;
+	socklen_t len;
+	int err;
+
+	len = sizeof(cred);
+	err = getsockopt(fd, SOL_SOCKET, SO_PEERCRED, (void *) &cred, &len);
+	if (err) {
+		eprintf("can't get sockopt, %m\n");
+		return -1;
+	}
+
+	if (cred.uid || cred.gid)
+		return -EPERM;
+
+	return 0;
+}
+
+int os_oom_adjust(void)
+{
+	int fd, err;
+	char path[64];
+
+	/* Avoid oom-killer */
+	sprintf(path, "/proc/%d/oom_adj", getpid());
+	fd = open(path, O_WRONLY);
+	if (fd < 0) {
+		eprintf("can't adjust oom-killer's pardon %s, %m\n", path);
+		return errno;
+	}
+	err = write(fd, "-17\n", 4);
+	if (err < 0) {
+		eprintf("can't adjust oom-killer's pardon %s, %m\n", path);
+		return errno;
+	}
+	close(fd);
+	return 0;
+}
+
+int os_blockdev_size(int fd, uint64_t *size)
+{
+	return ioctl(fd, BLKGETSIZE64, size);
+}
diff --git a/usr/mgmt.c b/usr/mgmt.c
index 5351b2c..b7b1a97 100644
--- a/usr/mgmt.c
+++ b/usr/mgmt.c
@@ -19,19 +19,13 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  * 02110-1301 USA
  */
-#include <ctype.h>
-#include <dirent.h>
 #include <errno.h>
-#include <fcntl.h>
 #include <inttypes.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <unistd.h>
 #include <sys/epoll.h>
 #include <sys/socket.h>
-#include <sys/stat.h>
-#include <sys/types.h>
 #include <sys/un.h>
 
 #include "list.h"
@@ -379,25 +373,6 @@ static int ipc_accept(int accept_fd)
 	return fd;
 }
 
-static int ipc_perm(int fd)
-{
-	struct ucred cred;
-	socklen_t len;
-	int err;
-
-	len = sizeof(cred);
-	err = getsockopt(fd, SOL_SOCKET, SO_PEERCRED, (void *) &cred, &len);
-	if (err) {
-		eprintf("can't get sockopt, %m\n");
-		return -1;
-	}
-
-	if (cred.uid || cred.gid)
-		return -EPERM;
-
-	return 0;
-}
-
 static void mtask_handler(int fd, int events, void *data)
 {
 	int err, len;
@@ -506,7 +481,7 @@ static void mgmt_event_handler(int accept_fd, int events, void *data)
 		return;
 	}
 
-	err = ipc_perm(fd);
+	err = os_ipc_perm(fd);
 	if (err < 0) {
 		eprintf("permission error\n");
 		goto out;
diff --git a/usr/os.h b/usr/os.h
index cd4dd71..c8e65a1 100644
--- a/usr/os.h
+++ b/usr/os.h
@@ -9,5 +9,10 @@
 int os_sync_file_range(int fd, __off64_t offset, __off64_t bytes,
 			unsigned int flags);
 
+int os_ipc_perm(int fd);
+
+int os_oom_adjust(void);
+
+int os_blockdev_size(int fd, uint64_t *size);
 
 #endif /* ndef __TGT_OS_H__*/
diff --git a/usr/tgtd.c b/usr/tgtd.c
index 8569d41..d243151 100644
--- a/usr/tgtd.c
+++ b/usr/tgtd.c
@@ -76,27 +76,6 @@ Target framework daemon, version %s\n\
 static void signal_catch(int signo) {
 }
 
-static int oom_adjust(void)
-{
-	int fd, err;
-	char path[64];
-
-	/* Avoid oom-killer */
-	sprintf(path, "/proc/%d/oom_adj", getpid());
-	fd = open(path, O_WRONLY);
-	if (fd < 0) {
-		fprintf(stderr, "can't adjust oom-killer's pardon %s, %m\n", path);
-		return errno;
-	}
-	err = write(fd, "-17\n", 4);
-	if (err < 0) {
-		fprintf(stderr, "can't adjust oom-killer's pardon %s, %m\n", path);
-		return errno;
-	}
-	close(fd);
-	return 0;
-}
-
 static int nr_file_adjust(void)
 {
 	int ret, fd, max = 1024 * 1024;
@@ -368,7 +347,7 @@ int main(int argc, char **argv)
 	if (is_daemon && daemon(0,0))
 		exit(1);
 
-	err = oom_adjust();
+	err = os_oom_adjust();
 	if (err)
 		exit(1);
 
diff --git a/usr/util.c b/usr/util.c
index 2f4f488..ac14a7b 100644
--- a/usr/util.c
+++ b/usr/util.c
@@ -101,7 +101,7 @@ int backed_file_open(char *path, int oflag, uint64_t *size)
 	if (S_ISREG(st.st_mode))
 		*size = st.st_size;
 	else if (S_ISBLK(st.st_mode)) {
-		err = ioctl(fd, BLKGETSIZE64, size);
+		err = os_blockdev_size(fd, size);
 		if (err < 0) {
 			eprintf("Cannot get size, %m\n");
 			goto close_fd;
-- 
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