From 727be1c1b83eae8480c27a2bbfd92b94957bbeb5 Mon Sep 17 00:00:00 2001 From: ericm Date: Tue, 19 Aug 2003 12:08:53 +0000 Subject: [PATCH] [liblustre]: merge LiuKai's cygwin patch - add portals/include/cygwin-ioctl.h - don't compile accepter.c in liblustre - add missing le-cpu convert macro - use windows API directly at some places --- lnet/include/linux/kp30.h | 2 ++ lnet/utils/Makefile.am | 4 +++ lnet/utils/debug.c | 30 +++++++++++++++---- lnet/utils/l_ioctl.c | 58 ++++++++++++++++++++++++++++++++----- lnet/utils/portals.c | 15 ++++++++++ lustre/portals/include/linux/kp30.h | 2 ++ lustre/portals/utils/Makefile.am | 4 +++ lustre/portals/utils/debug.c | 30 +++++++++++++++---- lustre/portals/utils/l_ioctl.c | 58 ++++++++++++++++++++++++++++++++----- lustre/portals/utils/portals.c | 15 ++++++++++ 10 files changed, 192 insertions(+), 26 deletions(-) diff --git a/lnet/include/linux/kp30.h b/lnet/include/linux/kp30.h index 2133391..e7b850d 100644 --- a/lnet/include/linux/kp30.h +++ b/lnet/include/linux/kp30.h @@ -595,6 +595,8 @@ extern void kportal_blockallsigs (void); # include #ifndef __CYGWIN__ # include +#else +# include #endif # include # include diff --git a/lnet/utils/Makefile.am b/lnet/utils/Makefile.am index d51e3b3..5b3968d 100644 --- a/lnet/utils/Makefile.am +++ b/lnet/utils/Makefile.am @@ -7,7 +7,11 @@ COMPILE = $(CC) -Wall -g -I$(srcdir)/../include LINK = $(CC) -o $@ +if LIBLUSTRE +sbin_PROGRAMS = ptlctl debugctl routerstat wirecheck +else sbin_PROGRAMS = acceptor ptlctl debugctl routerstat wirecheck +endif lib_LIBRARIES = libptlctl.a acceptor_SOURCES = acceptor.c # -lefence diff --git a/lnet/utils/debug.c b/lnet/utils/debug.c index 0a009d2..e44d92a 100644 --- a/lnet/utils/debug.c +++ b/lnet/utils/debug.c @@ -31,19 +31,24 @@ #include #include #include -#include +#ifndef __CYGWIN__ +# include +#endif #include #include #include #include #include + +#ifdef __KERNEL__ #define BUG() /* workaround for module.h includes */ #include #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)) #include #endif +#endif /* __KERNEL__ */ #include #include @@ -410,13 +415,18 @@ int jt_dbg_debug_file(int argc, char **argv) strerror(errno)); return -1; } -#warning FIXME: cleanup fstat issue here -#ifndef SYS_fstat64 -#define __SYS_fstat__ SYS_fstat -#else -#define __SYS_fstat__ SYS_fstat64 + +#ifndef __CYGWIN__ +# warning FIXME: cleanup fstat issue here +# ifndef SYS_fstat64 +# define __SYS_fstat__ SYS_fstat +# else +# define __SYS_fstat__ SYS_fstat64 #endif rc = syscall(__SYS_fstat__, fd, &statbuf); +#else + rc = fstat(fd, &statbuf); +#endif if (rc < 0) { fprintf(stderr, "fstat failed: %s\n", strerror(errno)); goto out; @@ -514,6 +524,7 @@ int jt_dbg_mark_debug_buf(int argc, char **argv) return 0; } +#ifdef __KERNEL__ int jt_dbg_modules(int argc, char **argv) { @@ -585,6 +596,13 @@ int jt_dbg_modules(int argc, char **argv) #endif /* linux 2.5 */ } +#else +int jt_dbg_modules(int argc, char **argv) +{ + return -1; +} +#endif /* __KERNEL__ */ + int jt_dbg_panic(int argc, char **argv) { int rc; diff --git a/lnet/utils/l_ioctl.c b/lnet/utils/l_ioctl.c index 722bb57..d574556 100644 --- a/lnet/utils/l_ioctl.c +++ b/lnet/utils/l_ioctl.c @@ -23,7 +23,6 @@ #include #include #include -#include #include #include #include @@ -35,6 +34,13 @@ #include #include +#ifndef __CYGWIN__ + #include +#else + #include + #include +#endif + struct ioc_dev { const char * dev_name; int dev_fd; @@ -207,17 +213,24 @@ l_ioctl(int dev_id, int opc, void *buf) int parse_dump(char * dump_file, int (*ioc_func)(int dev_id, int opc, void *)) { - int fd, line =0; + int line =0; struct stat st; - char *buf, *end; + char *start, *buf, *end; +#ifndef __CYGWIN__ + int fd; +#else + HANDLE fd, hmap; + DWORD size; +#endif +#ifndef __CYGWIN__ fd = syscall(SYS_open, dump_file, O_RDONLY); #warning FIXME: cleanup fstat issue here #ifndef SYS_fstat64 -#define __SYS_fstat__ SYS_fstat +# define __SYS_fstat__ SYS_fstat #else -#define __SYS_fstat__ SYS_fstat64 +# define __SYS_fstat__ SYS_fstat64 #endif if (syscall(__SYS_fstat__, fd, &st)) { perror("stat fails"); @@ -229,9 +242,32 @@ parse_dump(char * dump_file, int (*ioc_func)(int dev_id, int opc, void *)) exit(1); } - buf = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE , fd, 0); - end = buf + st.st_size; + start = buf = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE , fd, 0); + end = start + st.st_size; close(fd); + if (start == MAP_FAILED) { + fprintf(stderr, "can't create file mapping\n"); + exit(1); + } +#else + fd = CreateFile(dump_file, GENERIC_READ, FILE_SHARE_READ, NULL, + OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); + size = GetFileSize(fd, NULL); + if (size < 1) { + fprintf(stderr, "KML is empty\n"); + exit(1); + } + + hmap = CreateFileMapping(fd, NULL, PAGE_READONLY, 0,0, NULL); + start = buf = MapViewOfFile(hmap, FILE_MAP_READ, 0, 0, 0); + end = buf + size; + CloseHandle(fd); + if (start == NULL) { + fprintf(stderr, "can't create file mapping\n"); + exit(1); + } +#endif /* __CYGWIN__ */ + while (buf < end) { struct dump_hdr *dump_hdr = (struct dump_hdr *) buf; struct portal_ioctl_hdr * data; @@ -264,6 +300,14 @@ parse_dump(char * dump_file, int (*ioc_func)(int dev_id, int opc, void *)) buf += data->ioc_len + sizeof(*dump_hdr); } + +#ifndef __CYGWIN__ + munmap(start, end - start); +#else + UnmapViewOfFile(start); + CloseHandle(hmap); +#endif + return 0; } diff --git a/lnet/utils/portals.c b/lnet/utils/portals.c index a89f4f7..c87b0952 100644 --- a/lnet/utils/portals.c +++ b/lnet/utils/portals.c @@ -35,6 +35,21 @@ #include #include +#ifdef __CYGWIN__ + +#include + +#warning assuming little endian + +#define __cpu_to_le64(x) ((__u64)(x)) +#define __le64_to_cpu(x) ((__u64)(x)) +#define __cpu_to_le32(x) ((__u32)(x)) +#define __le32_to_cpu(x) ((__u32)(x)) +#define __cpu_to_le16(x) ((__u16)(x)) +#define __le16_to_cpu(x) ((__u16)(x)) + +#endif /* __CYGWIN__ */ + #include #include #include diff --git a/lustre/portals/include/linux/kp30.h b/lustre/portals/include/linux/kp30.h index 2133391..e7b850d 100644 --- a/lustre/portals/include/linux/kp30.h +++ b/lustre/portals/include/linux/kp30.h @@ -595,6 +595,8 @@ extern void kportal_blockallsigs (void); # include #ifndef __CYGWIN__ # include +#else +# include #endif # include # include diff --git a/lustre/portals/utils/Makefile.am b/lustre/portals/utils/Makefile.am index d51e3b3..5b3968d 100644 --- a/lustre/portals/utils/Makefile.am +++ b/lustre/portals/utils/Makefile.am @@ -7,7 +7,11 @@ COMPILE = $(CC) -Wall -g -I$(srcdir)/../include LINK = $(CC) -o $@ +if LIBLUSTRE +sbin_PROGRAMS = ptlctl debugctl routerstat wirecheck +else sbin_PROGRAMS = acceptor ptlctl debugctl routerstat wirecheck +endif lib_LIBRARIES = libptlctl.a acceptor_SOURCES = acceptor.c # -lefence diff --git a/lustre/portals/utils/debug.c b/lustre/portals/utils/debug.c index 0a009d2..e44d92a 100644 --- a/lustre/portals/utils/debug.c +++ b/lustre/portals/utils/debug.c @@ -31,19 +31,24 @@ #include #include #include -#include +#ifndef __CYGWIN__ +# include +#endif #include #include #include #include #include + +#ifdef __KERNEL__ #define BUG() /* workaround for module.h includes */ #include #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)) #include #endif +#endif /* __KERNEL__ */ #include #include @@ -410,13 +415,18 @@ int jt_dbg_debug_file(int argc, char **argv) strerror(errno)); return -1; } -#warning FIXME: cleanup fstat issue here -#ifndef SYS_fstat64 -#define __SYS_fstat__ SYS_fstat -#else -#define __SYS_fstat__ SYS_fstat64 + +#ifndef __CYGWIN__ +# warning FIXME: cleanup fstat issue here +# ifndef SYS_fstat64 +# define __SYS_fstat__ SYS_fstat +# else +# define __SYS_fstat__ SYS_fstat64 #endif rc = syscall(__SYS_fstat__, fd, &statbuf); +#else + rc = fstat(fd, &statbuf); +#endif if (rc < 0) { fprintf(stderr, "fstat failed: %s\n", strerror(errno)); goto out; @@ -514,6 +524,7 @@ int jt_dbg_mark_debug_buf(int argc, char **argv) return 0; } +#ifdef __KERNEL__ int jt_dbg_modules(int argc, char **argv) { @@ -585,6 +596,13 @@ int jt_dbg_modules(int argc, char **argv) #endif /* linux 2.5 */ } +#else +int jt_dbg_modules(int argc, char **argv) +{ + return -1; +} +#endif /* __KERNEL__ */ + int jt_dbg_panic(int argc, char **argv) { int rc; diff --git a/lustre/portals/utils/l_ioctl.c b/lustre/portals/utils/l_ioctl.c index 722bb57..d574556 100644 --- a/lustre/portals/utils/l_ioctl.c +++ b/lustre/portals/utils/l_ioctl.c @@ -23,7 +23,6 @@ #include #include #include -#include #include #include #include @@ -35,6 +34,13 @@ #include #include +#ifndef __CYGWIN__ + #include +#else + #include + #include +#endif + struct ioc_dev { const char * dev_name; int dev_fd; @@ -207,17 +213,24 @@ l_ioctl(int dev_id, int opc, void *buf) int parse_dump(char * dump_file, int (*ioc_func)(int dev_id, int opc, void *)) { - int fd, line =0; + int line =0; struct stat st; - char *buf, *end; + char *start, *buf, *end; +#ifndef __CYGWIN__ + int fd; +#else + HANDLE fd, hmap; + DWORD size; +#endif +#ifndef __CYGWIN__ fd = syscall(SYS_open, dump_file, O_RDONLY); #warning FIXME: cleanup fstat issue here #ifndef SYS_fstat64 -#define __SYS_fstat__ SYS_fstat +# define __SYS_fstat__ SYS_fstat #else -#define __SYS_fstat__ SYS_fstat64 +# define __SYS_fstat__ SYS_fstat64 #endif if (syscall(__SYS_fstat__, fd, &st)) { perror("stat fails"); @@ -229,9 +242,32 @@ parse_dump(char * dump_file, int (*ioc_func)(int dev_id, int opc, void *)) exit(1); } - buf = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE , fd, 0); - end = buf + st.st_size; + start = buf = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE , fd, 0); + end = start + st.st_size; close(fd); + if (start == MAP_FAILED) { + fprintf(stderr, "can't create file mapping\n"); + exit(1); + } +#else + fd = CreateFile(dump_file, GENERIC_READ, FILE_SHARE_READ, NULL, + OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); + size = GetFileSize(fd, NULL); + if (size < 1) { + fprintf(stderr, "KML is empty\n"); + exit(1); + } + + hmap = CreateFileMapping(fd, NULL, PAGE_READONLY, 0,0, NULL); + start = buf = MapViewOfFile(hmap, FILE_MAP_READ, 0, 0, 0); + end = buf + size; + CloseHandle(fd); + if (start == NULL) { + fprintf(stderr, "can't create file mapping\n"); + exit(1); + } +#endif /* __CYGWIN__ */ + while (buf < end) { struct dump_hdr *dump_hdr = (struct dump_hdr *) buf; struct portal_ioctl_hdr * data; @@ -264,6 +300,14 @@ parse_dump(char * dump_file, int (*ioc_func)(int dev_id, int opc, void *)) buf += data->ioc_len + sizeof(*dump_hdr); } + +#ifndef __CYGWIN__ + munmap(start, end - start); +#else + UnmapViewOfFile(start); + CloseHandle(hmap); +#endif + return 0; } diff --git a/lustre/portals/utils/portals.c b/lustre/portals/utils/portals.c index a89f4f7..c87b0952 100644 --- a/lustre/portals/utils/portals.c +++ b/lustre/portals/utils/portals.c @@ -35,6 +35,21 @@ #include #include +#ifdef __CYGWIN__ + +#include + +#warning assuming little endian + +#define __cpu_to_le64(x) ((__u64)(x)) +#define __le64_to_cpu(x) ((__u64)(x)) +#define __cpu_to_le32(x) ((__u32)(x)) +#define __le32_to_cpu(x) ((__u32)(x)) +#define __cpu_to_le16(x) ((__u16)(x)) +#define __le16_to_cpu(x) ((__u16)(x)) + +#endif /* __CYGWIN__ */ + #include #include #include -- 1.8.3.1