]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
Fix up auto-detection of available libc features being used by xfs_io; including...
authorNathan Scott <nathans@sgi.com>
Mon, 9 Aug 2004 05:41:55 +0000 (05:41 +0000)
committerNathan Scott <nathans@sgi.com>
Mon, 9 Aug 2004 05:41:55 +0000 (05:41 +0000)
14 files changed:
aclocal.m4
configure.in
include/builddefs.in
io/Makefile
io/command.c
io/command.h
io/fadvise.c
io/init.c
io/io.h
io/madvise.c [new file with mode: 0644]
io/mincore.c [new file with mode: 0644]
io/mmap.c
m4/Makefile
m4/package_libcdev.m4 [new file with mode: 0644]

index c274667b5d479a7e1ed43fb6e2068536dfc81513..1eb6831e9800a78e8376eb152a3ae2198e9f6d85 100644 (file)
@@ -232,6 +232,142 @@ AC_DEFUN([AC_PACKAGE_NEED_PTHREADMUTEXINIT],
     AC_SUBST(libpthread)
   ])
 
+# 
+# Check if we have a working fadvise system call
+# 
+AC_DEFUN([AC_HAVE_FADVISE],
+  [ AC_MSG_CHECKING([for fadvise ])
+    AC_TRY_COMPILE([
+#define _GNU_SOURCE
+#define _FILE_OFFSET_BITS 64
+#include <fcntl.h>
+    ], [
+       posix_fadvise(0, 1, 0, 0);
+    ], have_fadvise=yes
+       AC_MSG_RESULT(yes),
+       AC_MSG_RESULT(no))
+    AC_SUBST(have_fadvise)
+  ])
+
+# 
+# Check if we have a working madvise system call
+# 
+AC_DEFUN([AC_HAVE_MADVISE],
+  [ AC_MSG_CHECKING([for madvise ])
+    AC_TRY_COMPILE([
+#define _GNU_SOURCE
+#define _FILE_OFFSET_BITS 64
+#include <sys/mman.h>
+    ], [
+       posix_madvise(0, 0, MADV_NORMAL);
+    ], have_madvise=yes
+       AC_MSG_RESULT(yes),
+       AC_MSG_RESULT(no))
+    AC_SUBST(have_madvise)
+  ])
+
+# 
+# Check if we have a working mincore system call
+# 
+AC_DEFUN([AC_HAVE_MINCORE],
+  [ AC_MSG_CHECKING([for mincore ])
+    AC_TRY_COMPILE([
+#define _GNU_SOURCE
+#define _FILE_OFFSET_BITS 64
+#include <sys/mman.h>
+    ], [
+       mincore(0, 0, 0);
+    ], have_mincore=yes
+       AC_MSG_RESULT(yes),
+       AC_MSG_RESULT(no))
+    AC_SUBST(have_mincore)
+  ])
+
+# 
+# Check if we have a working sendfile system call
+# 
+AC_DEFUN([AC_HAVE_SENDFILE],
+  [ AC_MSG_CHECKING([for sendfile ])
+    AC_TRY_COMPILE([
+#define _GNU_SOURCE
+#define _FILE_OFFSET_BITS 64
+#include <sys/sendfile.h>
+    ], [
+         sendfile(0, 0, 0, 0);
+    ], have_sendfile=yes
+       AC_MSG_RESULT(yes),
+       AC_MSG_RESULT(no))
+    AC_SUBST(have_sendfile)
+  ])
+
+# 
+# Check if we have a working fadvise system call
+# 
+AC_DEFUN([AC_HAVE_FADVISE],
+  [ AC_MSG_CHECKING([for fadvise ])
+    AC_TRY_COMPILE([
+#define _GNU_SOURCE
+#define _FILE_OFFSET_BITS 64
+#include <fcntl.h>
+    ], [
+       posix_fadvise(0, 1, 0, 0);
+    ], have_fadvise=yes
+       AC_MSG_RESULT(yes),
+       AC_MSG_RESULT(no))
+    AC_SUBST(have_fadvise)
+  ])
+
+# 
+# Check if we have a working madvise system call
+# 
+AC_DEFUN([AC_HAVE_MADVISE],
+  [ AC_MSG_CHECKING([for madvise ])
+    AC_TRY_COMPILE([
+#define _GNU_SOURCE
+#define _FILE_OFFSET_BITS 64
+#include <sys/mman.h>
+    ], [
+       posix_madvise(0, 0, MADV_NORMAL);
+    ], have_madvise=yes
+       AC_MSG_RESULT(yes),
+       AC_MSG_RESULT(no))
+    AC_SUBST(have_madvise)
+  ])
+
+# 
+# Check if we have a working mincore system call
+# 
+AC_DEFUN([AC_HAVE_MINCORE],
+  [ AC_MSG_CHECKING([for mincore ])
+    AC_TRY_COMPILE([
+#define _GNU_SOURCE
+#define _FILE_OFFSET_BITS 64
+#include <sys/mman.h>
+    ], [
+       mincore(0, 0, 0);
+    ], have_mincore=yes
+       AC_MSG_RESULT(yes),
+       AC_MSG_RESULT(no))
+    AC_SUBST(have_mincore)
+  ])
+
+# 
+# Check if we have a working sendfile system call
+# 
+AC_DEFUN([AC_HAVE_SENDFILE],
+  [ AC_MSG_CHECKING([for sendfile ])
+    AC_TRY_COMPILE([
+#define _GNU_SOURCE
+#define _FILE_OFFSET_BITS 64
+#include <sys/sendfile.h>
+    ], [
+         sendfile(0, 0, 0, 0);
+    ], have_sendfile=yes
+       AC_MSG_RESULT(yes),
+       AC_MSG_RESULT(no))
+    AC_SUBST(have_sendfile)
+  ])
+
 # 
 # Check if we have a type for the pointer's size integer (__psint_t)
 # 
index d12087bd3638c2daa9281d6842658b812efcfa12..c3a2a4a2ebfaa55f4506944f3d32b1a08c43e890 100644 (file)
@@ -34,6 +34,11 @@ AC_PACKAGE_NEED_UUIDCOMPARE
 AC_PACKAGE_NEED_PTHREAD_H
 AC_PACKAGE_NEED_PTHREADMUTEXINIT
 
+AC_HAVE_FADVISE
+AC_HAVE_MADVISE
+AC_HAVE_MINCORE
+AC_HAVE_SENDFILE
+
 AC_TYPE_PSINT
 AC_TYPE_PSUNSIGNED
 AC_SIZEOF_POINTERS_AND_LONG
index 6ff453a42addf4be42671fa216d0c04a94617430..7710215aa5a19770aeb77a06608ebf9dd6a07bd8 100644 (file)
@@ -1,5 +1,5 @@
 #
-# Copyright (c) 2003 Silicon Graphics, Inc.  All Rights Reserved.
+# Copyright (c) 2004 Silicon Graphics, Inc.  All Rights Reserved.
 #
 # This program is free software; you can redistribute it and/or modify it
 # under the terms of version 2 of the GNU General Public License as
@@ -94,6 +94,11 @@ ENABLE_EDITLINE = @enable_editline@
 ENABLE_READLINE = @enable_readline@
 HAVE_ZIPPED_MANPAGES = @have_zipped_manpages@
 
+HAVE_FADVISE = @have_fadvise@
+HAVE_MADVISE = @have_madvise@
+HAVE_MINCORE = @have_mincore@
+HAVE_SENDFILE = @have_sendfile@
+
 ifeq ($(PKG_PLATFORM),linux)
 PCFLAGS = -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64
 endif
index da5d69eabf7e5210576e46d899da8ee02ec3811e..6a39d5c9cbca56fa789351aff8595229597b3f67 100644 (file)
@@ -41,11 +41,32 @@ CFILES = command.c input.c init.c \
        mmap.c open.c pread.c prealloc.c pwrite.c quit.c \
        truncate.c
 
-ifeq ($(PKG_PLATFORM),linux)
-CFILES += fadvise.c sendfile.c
-LCFLAGS += -DHAVE_FADVISE -DHAVE_SENDFILE
+ifeq ($(HAVE_FADVISE),yes)
+CFILES += fadvise.c
+LCFLAGS += -DHAVE_FADVISE
 else
-LSRCFILES += fadvise.c sendfile.c
+LSRCFILES += fadvise.c
+endif
+
+ifeq ($(HAVE_MADVISE),yes)
+CFILES += madvise.c
+LCFLAGS += -DHAVE_MADVISE
+else
+LSRCFILES += madvise.c
+endif
+
+ifeq ($(HAVE_MINCORE),yes)
+CFILES += mincore.c
+LCFLAGS += -DHAVE_MINCORE
+else
+LSRCFILES += mincore.c
+endif
+
+ifeq ($(HAVE_SENDFILE),yes)
+CFILES += sendfile.c
+LCFLAGS += -DHAVE_SENDFILE
+else
+LSRCFILES += sendfile.c
 endif
 
 ifneq ($(PKG_PLATFORM),irix)
index 9370d5583baa75728e02f9696ec7e88b7a0fadf7..041ad76f632afabf9d1f188a55cf5fa28dfffdbb 100644 (file)
@@ -123,25 +123,3 @@ find_command(
        }
        return NULL;
 }
-
-void
-init_commands(void)
-{
-       bmap_init();
-       fadvise_init();
-       file_init();
-       freeze_init();
-       fsync_init();
-       help_init();
-       inject_init();
-       mmap_init();
-       open_init();
-       pread_init();
-       prealloc_init();
-       pwrite_init();
-       quit_init();
-       resblks_init();
-       sendfile_init();
-       shutdown_init();
-       truncate_init();
-}
index 4f331560ac6f8f0e18a146eaa0c5701e74bb4e33..fb3377a792e1b04c7f85f6c4f7db8ebc12777863 100644 (file)
@@ -59,48 +59,4 @@ extern void          add_command(const cmdinfo_t *ci);
 extern int             command_usage(const cmdinfo_t *ci);
 extern int             command(int argc, char **argv);
 extern const cmdinfo_t *find_command(const char *cmd);
-extern void            init_commands(void);
 
-extern void            bmap_init(void);
-extern void            file_init(void);
-extern void            freeze_init(void);
-extern void            fsync_init(void);
-extern void            help_init(void);
-extern void            inject_init(void);
-extern void            mmap_init(void);
-extern void            open_init(void);
-extern void            pread_init(void);
-extern void            prealloc_init(void);
-extern void            pwrite_init(void);
-extern void            quit_init(void);
-extern void            truncate_init(void);
-
-#ifdef HAVE_FADVISE
-extern void            fadvise_init(void);
-#else
-#define fadvise_init() do { } while (0)
-#endif
-
-#ifdef HAVE_INJECT
-extern void            inject_init(void);
-#else
-#define inject_init()  do { } while (0)
-#endif
-
-#ifdef HAVE_RESBLKS
-extern void            resblks_init(void);
-#else
-#define resblks_init() do { } while (0)
-#endif
-
-#ifdef HAVE_SENDFILE
-extern void            sendfile_init(void);
-#else
-#define sendfile_init()        do { } while (0)
-#endif
-
-#ifdef HAVE_SHUTDOWN
-extern void            shutdown_init(void);
-#else
-#define shutdown_init()        do { } while (0)
-#endif
index 04508148eed71e7feba26821a90ef9c6d2052274..29dede4b8317f206394c4b15906da7701acf307a 100644 (file)
 
 static cmdinfo_t fadvise_cmd;
 
-#if !defined(__NR_fadvise64)
-# if defined(__i386__)
-#   define __NR_fadvise64 250
-# elif defined(__ia64__)
-#   define __NR_fadvise64 1234
-# elif defined(__powerpc__)
-#   define __NR_fadvise64 233
-# endif
-#endif
-
-static int
-fadvise64(int fd, off64_t offset, size_t len, int advise)
-{
-#ifdef __NR_fadvise64
-       return syscall(__NR_fadvise64, fd, offset, len, advise);
-#else
-       errno = ENOSYS; return -1;
-#endif
-}
-
 static void
 fadvise_help(void)
 {
@@ -139,7 +119,7 @@ fadvise_f(
                return command_usage(&fadvise_cmd);
        }
 
-       if (fadvise64(file->fd, offset, length, advise) < 0) {
+       if (posix_fadvise64(file->fd, offset, length, advise) < 0) {
                perror("fadvise");
                return 0;
        }
index 3b7db9ca78c3ddba581111b2a4541182bb2e125b..e0135f0f53425b005c4f6ecf09f0cf0df53993fb 100644 (file)
--- a/io/init.c
+++ b/io/init.c
@@ -52,6 +52,28 @@ usage(void)
        exit(1);
 }
 
+void
+init_commands(void)
+{
+       bmap_init();
+       fadvise_init();
+       file_init();
+       freeze_init();
+       fsync_init();
+       help_init();
+       inject_init();
+       mmap_init();
+       open_init();
+       pread_init();
+       prealloc_init();
+       pwrite_init();
+       quit_init();
+       resblks_init();
+       sendfile_init();
+       shutdown_init();
+       truncate_init();
+}
+
 void
 init(
        int             argc,
diff --git a/io/io.h b/io/io.h
index eb1c8516ff1f0fb8f437ede5524efd60c6d5d6de..c305c3d9adc03c03cbc65a8ddb0a891a7b706e1a 100644 (file)
--- a/io/io.h
+++ b/io/io.h
@@ -69,6 +69,7 @@ extern mmap_region_t  *maptable;      /* mmap'd region array */
 extern int             mapcount;       /* #entries in the mapping table */
 extern mmap_region_t   *mapping;       /* active mapping table entry */
 extern int maplist_f(void);
+extern void *check_mapping_range(mmap_region_t *, off64_t, size_t, int);
 
 /*
  * Various xfs_io helper routines/globals
@@ -84,3 +85,60 @@ extern int           alloc_buffer(ssize_t, int, unsigned int);
 extern int             read_buffer(int, off64_t, long long, long long *,
                                        int, int);
 extern void            dump_buffer(off64_t, ssize_t);
+
+extern void            bmap_init(void);
+extern void            file_init(void);
+extern void            freeze_init(void);
+extern void            fsync_init(void);
+extern void            help_init(void);
+extern void            inject_init(void);
+extern void            mmap_init(void);
+extern void            open_init(void);
+extern void            pread_init(void);
+extern void            prealloc_init(void);
+extern void            pwrite_init(void);
+extern void            quit_init(void);
+extern void            truncate_init(void);
+
+#ifdef HAVE_FADVISE
+extern void            fadvise_init(void);
+#else
+#define fadvise_init() do { } while (0)
+#endif
+
+#ifdef HAVE_INJECT
+extern void            inject_init(void);
+#else
+#define inject_init()  do { } while (0)
+#endif
+
+#ifdef HAVE_RESBLKS
+extern void            resblks_init(void);
+#else
+#define resblks_init() do { } while (0)
+#endif
+
+#ifdef HAVE_SENDFILE
+extern void            sendfile_init(void);
+#else
+#define sendfile_init()        do { } while (0)
+#endif
+
+#ifdef HAVE_SHUTDOWN
+extern void            shutdown_init(void);
+#else
+#define shutdown_init()        do { } while (0)
+#endif
+
+#ifdef HAVE_MADVISE
+extern void            madvise_init(void);
+#else
+#define madvise_init() do { } while (0)
+#endif
+
+#ifdef HAVE_MINCORE
+extern void            mincore_init(void);
+#else
+#define mincore_init() do { } while (0)
+#endif
+
diff --git a/io/madvise.c b/io/madvise.c
new file mode 100644 (file)
index 0000000..a687c33
--- /dev/null
@@ -0,0 +1,141 @@
+/*
+ * Copyright (c) 2004 Silicon Graphics, Inc.  All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it would be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * Further, this software is distributed without any warranty that it is
+ * free of the rightful claim of any third person regarding infringement
+ * or the like.  Any license provided herein, whether implied or
+ * otherwise, applies only to this software file.  Patent licenses, if
+ * any, provided herein do not apply to combinations of this program with
+ * other software, or any other product whatsoever.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write the Free Software Foundation, Inc., 59
+ * Temple Place - Suite 330, Boston MA 02111-1307, USA.
+ *
+ * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
+ * Mountain View, CA  94043, or:
+ *
+ * http://www.sgi.com
+ *
+ * For further information regarding this notice, see:
+ *
+ * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
+ */
+
+#include <xfs/libxfs.h>
+#include <sys/mman.h>
+#include "command.h"
+#include "input.h"
+#include "init.h"
+#include "io.h"
+
+static cmdinfo_t madvise_cmd;
+
+static void
+madvise_help(void)
+{
+       printf(_(
+"\n"
+" advise the page cache about access patterns expected for a mapping\n"
+"\n"
+" Modifies page cache behavior when operating on the current mapping.\n"
+" The range arguments are required by some advise commands ([*] below).\n"
+" With no arguments, the POSIX_MADV_NORMAL advice is implied.\n"
+" -d -- don't need these pages (POSIX_MADV_DONTNEED) [*]\n"
+" -r -- expect random page references (POSIX_MADV_RANDOM)\n"
+" -s -- expect sequential page references (POSIX_MADV_SEQUENTIAL)\n"
+" -w -- will need these pages (POSIX_MADV_WILLNEED) [*]\n"
+" Notes:\n"
+"   NORMAL sets the default readahead setting on the file.\n"
+"   RANDOM sets the readahead setting on the file to zero.\n"
+"   SEQUENTIAL sets double the default readahead setting on the file.\n"
+"   WILLNEED forces the maximum readahead.\n"
+"\n"));
+}
+
+int
+madvise_f(
+       int             argc,
+       char            **argv)
+{
+       off64_t         offset;
+       size_t          length;
+       void            *start;
+       int             advise = MADV_NORMAL;
+       int             c, blocksize, sectsize;
+
+       while ((c = getopt(argc, argv, "drsw")) != EOF) {
+               switch (c) {
+               case 'd':       /* Don't need these pages */
+                       advise = MADV_DONTNEED;
+                       break;
+               case 'r':       /* Expect random page references */
+                       advise = MADV_RANDOM;
+                       break;
+               case 's':       /* Expect sequential page references */
+                       advise = MADV_SEQUENTIAL;
+                       break;
+               case 'w':       /* Will need these pages */
+                       advise = MADV_WILLNEED;
+                       break;
+               default:
+                       return command_usage(&madvise_cmd);
+               }
+       }
+
+       if (optind == argc) {
+               offset = mapping->offset;
+               length = mapping->length;
+       } else if (optind == argc - 2) {
+               init_cvtnum(&blocksize, &sectsize);
+               offset = cvtnum(blocksize, sectsize, argv[optind]);
+               if (offset < 0) {
+                       printf(_("non-numeric offset argument -- %s\n"),
+                               argv[optind]);
+                       return 0;
+               }
+               optind++;
+               length = cvtnum(blocksize, sectsize, argv[optind]);
+               if (length < 0) {
+                       printf(_("non-numeric length argument -- %s\n"),
+                               argv[optind]);
+                       return 0;
+               }
+       } else {
+               return command_usage(&madvise_cmd);
+       }
+
+       start = check_mapping_range(mapping, offset, length, 1);
+       if (!start)
+               return 0;
+
+       if (madvise(start, length, advise) < 0) {
+               perror("madvise");
+               return 0;
+       }
+       return 0;
+}
+
+void
+madvise_init(void)
+{
+       madvise_cmd.name = _("madvise");
+       madvise_cmd.altname = _("ma");
+       madvise_cmd.cfunc = madvise_f;
+       madvise_cmd.argmin = 0;
+       madvise_cmd.argmax = -1;
+       madvise_cmd.flags = CMD_NOFILE_OK | CMD_FOREIGN_OK;
+       madvise_cmd.args = _("[-drsw] [off len]");
+       madvise_cmd.oneline = _("give advice about use of memory");
+       madvise_cmd.help = madvise_help;
+
+       add_command(&madvise_cmd);
+}
diff --git a/io/mincore.c b/io/mincore.c
new file mode 100644 (file)
index 0000000..80b4ac4
--- /dev/null
@@ -0,0 +1,134 @@
+/*
+ * Copyright (c) 2004 Silicon Graphics, Inc.  All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it would be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * Further, this software is distributed without any warranty that it is
+ * free of the rightful claim of any third person regarding infringement
+ * or the like.  Any license provided herein, whether implied or
+ * otherwise, applies only to this software file.  Patent licenses, if
+ * any, provided herein do not apply to combinations of this program with
+ * other software, or any other product whatsoever.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write the Free Software Foundation, Inc., 59
+ * Temple Place - Suite 330, Boston MA 02111-1307, USA.
+ *
+ * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
+ * Mountain View, CA  94043, or:
+ *
+ * http://www.sgi.com
+ *
+ * For further information regarding this notice, see:
+ *
+ * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
+ */
+
+#include <xfs/libxfs.h>
+#include <sys/mman.h>
+#include "command.h"
+#include "input.h"
+#include "init.h"
+#include "io.h"
+
+static cmdinfo_t mincore_cmd;
+
+int
+mincore_f(
+       int             argc,
+       char            **argv)
+{
+       off64_t         offset;
+       size_t          length;
+       void            *start;
+       void            *current, *previous;
+       unsigned char   *vec;
+       int             i, blocksize, sectsize;
+
+       if (argc == 1) {
+               offset = mapping->offset;
+               length = mapping->length;
+       } else if (argc == 3) {
+               init_cvtnum(&blocksize, &sectsize);
+               offset = cvtnum(blocksize, sectsize, argv[1]);
+               if (offset < 0) {
+                       printf(_("non-numeric offset argument -- %s\n"),
+                               argv[1]);
+                       return 0;
+               }
+               length = cvtnum(blocksize, sectsize, argv[2]);
+               if (length < 0) {
+                       printf(_("non-numeric length argument -- %s\n"),
+                               argv[2]);
+                       return 0;
+               }
+       } else {
+               return command_usage(&mincore_cmd);
+       }
+
+       start = check_mapping_range(mapping, offset, length, 1);
+       if (!start)
+               return 0;
+
+       vec = calloc(length/pagesize, sizeof(unsigned char));
+       if (!vec) {
+               perror("calloc");
+               return 0;
+       }
+
+       if (mincore(start, length, vec) < 0) {
+               perror("mincore");
+               free(vec);
+               return 0;
+       }
+
+       previous = NULL;
+       current = start;
+       for (i = 0; i < length/pagesize; i++, current += pagesize) {
+               if (vec[i]) {
+                       if (!previous) {        /* print start address */
+                               printf("0x%lx - ", (unsigned long)current);
+                               previous = start + (i * pagesize);
+                       }
+               } else if (previous) {          /* print end and page count */
+                       printf(_("0x%lx  %lu pages (%llu : %lu)\n"),
+                               (unsigned long)current,
+                               (unsigned long)(current - previous) / pagesize,
+                               (unsigned long long)offset +
+                                       (unsigned long long)(previous - start),
+                               (unsigned long)(current - previous));
+                       previous = NULL;
+               }
+       }
+       if (previous)
+               printf(_("0x%lx  %lu pages (%llu : %lu)\n"),
+                       (unsigned long)current,
+                       (unsigned long)(current - previous) / pagesize,
+                       (unsigned long long)offset +
+                               (unsigned long long)(previous - start),
+                       (unsigned long)(current - previous));
+
+       free(vec);
+       return 0;
+}
+
+void
+mincore_init(void)
+{
+       mincore_cmd.name = _("mincore");
+       mincore_cmd.altname = _("mi");
+       mincore_cmd.cfunc = mincore_f;
+       mincore_cmd.argmin = 0;
+       mincore_cmd.argmax = 2;
+       mincore_cmd.flags = CMD_NOFILE_OK | CMD_FOREIGN_OK;
+       mincore_cmd.args = _("[off len]");
+       mincore_cmd.oneline = _("find mapping pages that are memory resident");
+
+       add_command(&mincore_cmd);
+}
index af7c3504b3e86e44cd9cf5a344cf1ae68059ba37..300eff08339a44e91f132c04112556fa74ab2b08 100644 (file)
--- a/io/mmap.c
+++ b/io/mmap.c
@@ -43,8 +43,6 @@ static cmdinfo_t mread_cmd;
 static cmdinfo_t msync_cmd;
 static cmdinfo_t munmap_cmd;
 static cmdinfo_t mwrite_cmd;
-static cmdinfo_t madvise_cmd;
-static cmdinfo_t mincore_cmd;
 
 mmap_region_t  *maptable;
 int            mapcount;
@@ -79,7 +77,7 @@ print_mapping(
                (long long)map->offset, (long)map->length);
 }
 
-static void *
+void *
 check_mapping_range(
        mmap_region_t   *map,
        off64_t         offset,
@@ -594,174 +592,6 @@ mwrite_f(
        return 0;
 }
 
-static void
-madvise_help(void)
-{
-       printf(_(
-"\n"
-" advise the page cache about access patterns expected for a mapping\n"
-"\n"
-" Modifies page cache behavior when operating on the current mapping.\n"
-" The range arguments are required by some advise commands ([*] below).\n"
-" With no arguments, the POSIX_MADV_NORMAL advice is implied.\n"
-" -d -- don't need these pages (POSIX_MADV_DONTNEED) [*]\n"
-" -r -- expect random page references (POSIX_MADV_RANDOM)\n"
-" -s -- expect sequential page references (POSIX_MADV_SEQUENTIAL)\n"
-" -w -- will need these pages (POSIX_MADV_WILLNEED) [*]\n"
-" Notes:\n"
-"   NORMAL sets the default readahead setting on the file.\n"
-"   RANDOM sets the readahead setting on the file to zero.\n"
-"   SEQUENTIAL sets double the default readahead setting on the file.\n"
-"   WILLNEED forces the maximum readahead.\n"
-"\n"));
-}
-
-int
-madvise_f(
-       int             argc,
-       char            **argv)
-{
-       off64_t         offset;
-       size_t          length;
-       void            *start;
-       int             advise = MADV_NORMAL;
-       int             c, blocksize, sectsize;
-
-       while ((c = getopt(argc, argv, "drsw")) != EOF) {
-               switch (c) {
-               case 'd':       /* Don't need these pages */
-                       advise = MADV_DONTNEED;
-                       break;
-               case 'r':       /* Expect random page references */
-                       advise = MADV_RANDOM;
-                       break;
-               case 's':       /* Expect sequential page references */
-                       advise = MADV_SEQUENTIAL;
-                       break;
-               case 'w':       /* Will need these pages */
-                       advise = MADV_WILLNEED;
-                       break;
-               default:
-                       return command_usage(&madvise_cmd);
-               }
-       }
-
-       if (optind == argc) {
-               offset = mapping->offset;
-               length = mapping->length;
-       } else if (optind == argc - 2) {
-               init_cvtnum(&blocksize, &sectsize);
-               offset = cvtnum(blocksize, sectsize, argv[optind]);
-               if (offset < 0) {
-                       printf(_("non-numeric offset argument -- %s\n"),
-                               argv[optind]);
-                       return 0;
-               }
-               optind++;
-               length = cvtnum(blocksize, sectsize, argv[optind]);
-               if (length < 0) {
-                       printf(_("non-numeric length argument -- %s\n"),
-                               argv[optind]);
-                       return 0;
-               }
-       } else {
-               return command_usage(&madvise_cmd);
-       }
-
-       start = check_mapping_range(mapping, offset, length, 1);
-       if (!start)
-               return 0;
-
-       if (madvise(start, length, advise) < 0) {
-               perror("madvise");
-               return 0;
-       }
-       return 0;
-}
-
-#if defined(__sgi__)
-int mincore(caddr_t p, size_t s, char *v) { errno = ENOSYS; return -1; }
-#endif
-
-int
-mincore_f(
-       int             argc,
-       char            **argv)
-{
-       off64_t         offset;
-       size_t          length;
-       void            *start;
-       void            *current, *previous;
-       unsigned char   *vec;
-       int             i, blocksize, sectsize;
-
-       if (argc == 1) {
-               offset = mapping->offset;
-               length = mapping->length;
-       } else if (argc == 3) {
-               init_cvtnum(&blocksize, &sectsize);
-               offset = cvtnum(blocksize, sectsize, argv[1]);
-               if (offset < 0) {
-                       printf(_("non-numeric offset argument -- %s\n"),
-                               argv[1]);
-                       return 0;
-               }
-               length = cvtnum(blocksize, sectsize, argv[2]);
-               if (length < 0) {
-                       printf(_("non-numeric length argument -- %s\n"),
-                               argv[2]);
-                       return 0;
-               }
-       } else {
-               return command_usage(&mincore_cmd);
-       }
-
-       start = check_mapping_range(mapping, offset, length, 1);
-       if (!start)
-               return 0;
-
-       vec = calloc(length/pagesize, sizeof(unsigned char));
-       if (!vec) {
-               perror("calloc");
-               return 0;
-       }
-
-       if (mincore(start, length, vec) < 0) {
-               perror("mincore");
-               free(vec);
-               return 0;
-       }
-
-       previous = NULL;
-       current = start;
-       for (i = 0; i < length/pagesize; i++, current += pagesize) {
-               if (vec[i]) {
-                       if (!previous) {        /* print start address */
-                               printf("0x%lx - ", (unsigned long)current);
-                               previous = start + (i * pagesize);
-                       }
-               } else if (previous) {          /* print end and page count */
-                       printf(_("0x%lx  %lu pages (%llu : %lu)\n"),
-                               (unsigned long)current,
-                               (unsigned long)(current - previous) / pagesize,
-                               (unsigned long long)offset +
-                                       (unsigned long long)(previous - start),
-                               (unsigned long)(current - previous));
-                       previous = NULL;
-               }
-       }
-       if (previous)
-               printf(_("0x%lx  %lu pages (%llu : %lu)\n"),
-                       (unsigned long)current,
-                       (unsigned long)(current - previous) / pagesize,
-                       (unsigned long long)offset +
-                               (unsigned long long)(previous - start),
-                       (unsigned long)(current - previous));
-
-       free(vec);
-       return 0;
-}
-
 void
 mmap_init(void)
 {
@@ -816,30 +646,9 @@ mmap_init(void)
                _("writes data into a region in the current memory mapping");
        mwrite_cmd.help = mwrite_help;
 
-       madvise_cmd.name = _("madvise");
-       madvise_cmd.altname = _("ma");
-       madvise_cmd.cfunc = madvise_f;
-       madvise_cmd.argmin = 0;
-       madvise_cmd.argmax = -1;
-       madvise_cmd.flags = CMD_NOFILE_OK | CMD_FOREIGN_OK;
-       madvise_cmd.args = _("[-drsw] [off len]");
-       madvise_cmd.oneline = _("give advice about use of memory");
-       madvise_cmd.help = madvise_help;
-
-       mincore_cmd.name = _("mincore");
-       mincore_cmd.altname = _("mi");
-       mincore_cmd.cfunc = mincore_f;
-       mincore_cmd.argmin = 0;
-       mincore_cmd.argmax = 2;
-       mincore_cmd.flags = CMD_NOFILE_OK | CMD_FOREIGN_OK;
-       mincore_cmd.args = _("[off len]");
-       mincore_cmd.oneline = _("find mapping pages that are memory resident");
-
        add_command(&mmap_cmd);
        add_command(&mread_cmd);
        add_command(&msync_cmd);
        add_command(&munmap_cmd);
        add_command(&mwrite_cmd);
-       add_command(&madvise_cmd);
-       add_command(&mincore_cmd);
 }
index 2d06fec1c4ef00b508b21ce5c7ca0ecc82a91993..61dccf96ef08a2b197c6196105cabbdfa324d2b0 100644 (file)
@@ -36,6 +36,7 @@ include $(TOPDIR)/include/builddefs
 LSRCFILES = \
        manual_format.m4 \
        package_globals.m4 \
+       package_libcdev.m4 \
        package_pthread.m4 \
        package_types.m4 \
        package_utilies.m4 \
diff --git a/m4/package_libcdev.m4 b/m4/package_libcdev.m4
new file mode 100644 (file)
index 0000000..d612da2
--- /dev/null
@@ -0,0 +1,67 @@
+# 
+# Check if we have a working fadvise system call
+# 
+AC_DEFUN([AC_HAVE_FADVISE],
+  [ AC_MSG_CHECKING([for fadvise ])
+    AC_TRY_COMPILE([
+#define _GNU_SOURCE
+#define _FILE_OFFSET_BITS 64
+#include <fcntl.h>
+    ], [
+       posix_fadvise(0, 1, 0, 0);
+    ], have_fadvise=yes
+       AC_MSG_RESULT(yes),
+       AC_MSG_RESULT(no))
+    AC_SUBST(have_fadvise)
+  ])
+
+# 
+# Check if we have a working madvise system call
+# 
+AC_DEFUN([AC_HAVE_MADVISE],
+  [ AC_MSG_CHECKING([for madvise ])
+    AC_TRY_COMPILE([
+#define _GNU_SOURCE
+#define _FILE_OFFSET_BITS 64
+#include <sys/mman.h>
+    ], [
+       posix_madvise(0, 0, MADV_NORMAL);
+    ], have_madvise=yes
+       AC_MSG_RESULT(yes),
+       AC_MSG_RESULT(no))
+    AC_SUBST(have_madvise)
+  ])
+
+# 
+# Check if we have a working mincore system call
+# 
+AC_DEFUN([AC_HAVE_MINCORE],
+  [ AC_MSG_CHECKING([for mincore ])
+    AC_TRY_COMPILE([
+#define _GNU_SOURCE
+#define _FILE_OFFSET_BITS 64
+#include <sys/mman.h>
+    ], [
+       mincore(0, 0, 0);
+    ], have_mincore=yes
+       AC_MSG_RESULT(yes),
+       AC_MSG_RESULT(no))
+    AC_SUBST(have_mincore)
+  ])
+
+# 
+# Check if we have a working sendfile system call
+# 
+AC_DEFUN([AC_HAVE_SENDFILE],
+  [ AC_MSG_CHECKING([for sendfile ])
+    AC_TRY_COMPILE([
+#define _GNU_SOURCE
+#define _FILE_OFFSET_BITS 64
+#include <sys/sendfile.h>
+    ], [
+         sendfile(0, 0, 0, 0);
+    ], have_sendfile=yes
+       AC_MSG_RESULT(yes),
+       AC_MSG_RESULT(no))
+    AC_SUBST(have_sendfile)
+  ])