歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Unix知識 >> BSD >> 把BSD上的istgt移植到Mac OS X上

把BSD上的istgt移植到Mac OS X上

日期:2017/2/28 14:24:27   编辑:BSD

istgt軟件簡介

istgt是跑在openSUSE/Debian/NetBSD/FreeBSD上的iscsi target軟件,工作在用戶進程模式下。

主頁為:http://shell.peach.ne.jp/aoyama/

這是一個日本人寫的軟件,請拋開xx因素先別鄙視日本人。

雖然FreeBSD和Mac OS X是近親,但是直接下載源代碼到OS X編譯安裝,運行時是會出錯的,而且不支持OS X的BSD子系統kqueue。需要修改源代碼的兩個文件然後編譯才能正常在OS X上運行。

兩年前我就已經改好了年末的一個版本,給作者發過郵件,可是那家伙不鳥,呵呵。

# tar zxf istgt-20141125.tar.gz
# cd istgt-20141125/src

1、istgt.h

# vi istgt.h
跳轉到128行,啟用kqueue支持,修改成如下補丁信息的+號一行

--- istgt.h.orig 2012-08-19 05:04:12.000000000 +0800
+++ istgt.h 2014-12-31 00:11:32.000000000 +0800
@@ -125,7 +125,7 @@
#else
#error "no signal for internal"
#endif
-#if defined (__FreeBSD__) || defined (__NetBSD__) || defined (__OpenBSD__)
+#if defined (__FreeBSD__) || defined (__NetBSD__) || defined (__OpenBSD__) || (defined(__APPLE__) && defined(__GNUC__))
#define ISTGT_USE_KQUEUE
#if defined (__FreeBSD__)
#define ISTGT_EV_SET(kevp,a,b,c,d,e,f) EV_SET((kevp),(a),(b),(c),(d),(e),(void *)(f))

2、istgt.c

# vi istgt.c

跳轉到1555行,再看1576行,你會發現,他把pthread_attr_init和istgt_uctl_init的前後順序搞反了。所以你需要調整一個段落的代碼順序

從1576到1630行的代碼,都要剪切放到原1555行的rc = istgt_uctl_init(istgt);之前

以下是補丁:

--- istgt.c.orig 2012-11-13 02:44:24.000000000 +0800
+++ istgt.c 2014-12-31 00:10:04.000000000 +0800
@@ -1552,27 +1552,6 @@ istgt_init(ISTGT_Ptr istgt)
istgt->discovery_auth_group);
}

- rc = istgt_uctl_init(istgt);
- if (rc < 0) {
- ISTGT_ERRLOG("istgt_uctl_init() failed\n");
- return -1;
- }
- rc = istgt_build_uctl_portal(istgt);
- if (rc < 0) {
- ISTGT_ERRLOG("istgt_build_uctl_portal() failed\n");
- return -1;
- }
- rc = istgt_build_portal_group_array(istgt);
- if (rc < 0) {
- ISTGT_ERRLOG("istgt_build_portal_array() failed\n");
- return -1;
- }
- rc = istgt_build_initiator_group_array(istgt);
- if (rc < 0) {
- ISTGT_ERRLOG("build_initiator_group_array() failed\n");
- return -1;
- }
-
rc = pthread_attr_init(&istgt->attr);
if (rc != 0) {
ISTGT_ERRLOG("pthread_attr_init() failed\n");
@@ -1629,6 +1608,27 @@ istgt_init(ISTGT_Ptr istgt)
return -1;
}

+ rc = istgt_uctl_init(istgt);
+ if (rc < 0) {
+ ISTGT_ERRLOG("istgt_uctl_init() failed\n");
+ return -1;
+ }
+ rc = istgt_build_uctl_portal(istgt);
+ if (rc < 0) {
+ ISTGT_ERRLOG("istgt_build_uctl_portal() failed\n");
+ return -1;
+ }
+ rc = istgt_build_portal_group_array(istgt);
+ if (rc < 0) {
+ ISTGT_ERRLOG("istgt_build_portal_array() failed\n");
+ return -1;
+ }
+ rc = istgt_build_initiator_group_array(istgt);
+ if (rc < 0) {
+ ISTGT_ERRLOG("build_initiator_group_array() failed\n");
+ return -1;
+ }
+
rc = pipe(istgt->sig_pipe);
if (rc != 0) {
ISTGT_ERRLOG("pipe() failed\n");

3、注意事項

istgt不支持scsi reservation協議,如果你需要模擬存儲鎖定LUN,請使用linux的iscsitarget。

Copyright © Linux教程網 All Rights Reserved