Whamcloud - gitweb
EX-4015 lipe: define lipe scheme module
authorJohn L. Hammond <jhammond@whamcloud.com>
Mon, 14 Feb 2022 18:14:41 +0000 (12:14 -0600)
committerJohn L. Hammond <jhammond@whamcloud.com>
Thu, 10 Mar 2022 17:24:43 +0000 (17:24 +0000)
Avoid spurious "possibly undefined symbol" warnings from the guile
compiler by placing all of the snarfed definitions into a "lipe"
module. Add the fid accessors to a "lipe fid" module.

Test-Parameters: testlist=sanity-lipe-scan3 facet=mds1
Signed-off-by: John L. Hammond <jhammond@whamcloud.com>
Change-Id: Ifbfee81422b1a3df22ee23f1945577c29e485aec
Reviewed-on: https://review.whamcloud.com/46525
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
lipe/lipe.spec.in
lipe/src/lipe_scan3/Makefile.am
lipe/src/lipe_scan3/lipe/fid.scm [new file with mode: 0644]
lipe/src/lipe_scan3/lipe_scan_functions.scm [deleted file]
lipe/src/lipe_scan3/ls3_main.c
lipe/src/lipe_scan3/scripts/lipe_scan3_script
lipe/src/lipe_scan3/tests/bad-test.scm
lipe/src/lipe_scan3/tests/fid.scm
lipe/src/lipe_scan3/tests/fnmatch.scm
lipe/src/lipe_scan3/tests/lipe.scm
lustre/tests/sanity-lipe-scan3.sh

index a7731f3..de3a2bc 100644 (file)
@@ -19,6 +19,8 @@ Version: @VERSION@
 Vendor: DataDirect Networks Inc.
 Prefix: %{_prefix}
 
+%define guile_site_dir %{_datadir}/guile/site/2.0
+
 %define __python %{_bindir}/python2
 
 %{!?python2_sitelib: %global python2_sitelib %(%{__python2} -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())")}
@@ -153,6 +155,7 @@ rm -rf $RPM_BUILD_ROOT
 mkdir -p $RPM_BUILD_ROOT%{_sbindir}
 mkdir -p $RPM_BUILD_ROOT%{_bindir}
 mkdir -p $RPM_BUILD_ROOT%{_libdir}
+mkdir -p $RPM_BUILD_ROOT%{guile_site_dir}
 mkdir -p $RPM_BUILD_ROOT%{python2_sitelib}
 mkdir -p $RPM_BUILD_ROOT%{_mandir}/man1
 mkdir -p $RPM_BUILD_ROOT%{_mandir}/man5
@@ -189,6 +192,9 @@ cp \
        src/lipe_scan2 \
        src/lipe_scan3/lipe_scan3 \
        $RPM_BUILD_ROOT%{_bindir}
+
+cp -a src/lipe_scan3/lipe $RPM_BUILD_ROOT%{guile_site_dir}
+
 %if %{with laudit}
 cp src/laudit \
        src/laudit-report \
@@ -326,6 +332,7 @@ rm -rf $RPM_BUILD_ROOT
 %{_bindir}/lipe_scan
 %{_bindir}/lipe_scan2
 %{_bindir}/lipe_scan3
+%{guile_site_dir}/*
 %{python2_sitelib}/pylipe
 %config(noreplace) %{_sysconfdir}/lipe_launch.json
 %{_mandir}/man1/lipe_scan.1*
index b4c3643..84a570d 100644 (file)
@@ -3,6 +3,9 @@ ACLOCAL_AMFLAGS = ${ALOCAL_FLAGS}
 
 if BUILD_SERVER
 
+EXTRA_DIST = \
+       lipe/fid.scm
+
 BUILT_SOURCES = ls3_main.x
 bin_PROGRAMS = lipe_scan3
 
diff --git a/lipe/src/lipe_scan3/lipe/fid.scm b/lipe/src/lipe_scan3/lipe/fid.scm
new file mode 100644 (file)
index 0000000..3c19603
--- /dev/null
@@ -0,0 +1,44 @@
+(define-module (lipe fid)
+  #:use-module (lipe)
+  #:use-module (ice-9 iconv) ; bytevector->string
+  #:use-module (rnrs bytevectors)
+  #:export (
+           fid?
+           fid=?
+           fid->string
+           string->fid
+           ))
+
+;; Note: The struct type <fid>, constructor (make-fid), printer, and
+;; slot accessors accessors (fid-{seq,oid,ver}), are defined in
+;; ls3_main.c.
+
+(set-struct-vtable-name! <fid> 'fid)
+
+(define-inlinable (%c-style-string->number s)
+    (cond
+     ((string-prefix? "0x" s)
+      (string->number (substring s 2) 16))
+     ((string-prefix? "0" s)
+      (string->number s 8))
+     (else
+      (string->number s 10))))
+
+(define (fid? x)
+  (and (struct? x)
+       (eq? (struct-vtable x) <fid>)))
+
+(define (fid=? x1 x2)
+  (and (= (fid-seq x1) (fid-seq x2))
+       (= (fid-oid x1) (fid-oid x2))
+       (= (fid-ver x1) (fid-ver x2))))
+
+(define (fid->string x)
+  (format #f "~a" x))
+
+(define (string->fid s)
+  (apply make-fid
+        (map %c-style-string->number
+             (string-split (string-trim-right (string-trim s #\[)
+                                              #\])
+                           #\:))))
diff --git a/lipe/src/lipe_scan3/lipe_scan_functions.scm b/lipe/src/lipe_scan3/lipe_scan_functions.scm
deleted file mode 100644 (file)
index 14a775f..0000000
+++ /dev/null
@@ -1,84 +0,0 @@
-;; lipe_scan3 common Scheme definitions
-(use-modules (rnrs bytevectors))
-(use-modules (ice-9 iconv)) ; bytevector->string
-;; (use-modules (ice-9 threads)) ; with-mutex
-
-(define S_IFMT   #o0170000)
-(define S_IFDIR  #o0040000)
-(define S_IFCHR  #o0020000)
-(define S_IFBLK  #o0060000)
-(define S_IFREG  #o0100000)
-(define S_IFIFO  #o0010000)
-(define S_IFLNK  #o0120000)
-(define S_IFSOCK #o0140000)
-
-(define (perm)
-  (logand (mode) #o07777))
-
-(define (type)
-  (logand (mode) S_IFMT))
-
-(define (char->type c)
-  (cond
-   ((eq? c #\d) S_IFDIR)
-   ((eq? c #\c) S_IFCHR)
-   ((eq? c #\b) S_IFBLK)
-   ((eq? c #\f) S_IFREG)
-   ((eq? c #\p) S_IFIFO)
-   ((eq? c #\l) S_IFLNK)
-   ((eq? c #\s) S_IFSOCK)))
-
-(define (type->char t)
-  (cond
-   ((= t S_IFDIR) #\d)
-   ((= t S_IFCHR) #\c)
-   ((= t S_IFBLK) #\b)
-   ((= t S_IFREG) #\f)
-   ((= t S_IFIFO) #\p)
-   ((= t S_IFLNK) #\l)
-   ((= t S_IFSOCK) #\s)))
-
-;; fid
-;;
-;; Note: The struct type <fid>, constructor (make-fid), and slot accessors
-;; accessors (fid-{seq,oid,ver}), are defined in ls3_main.c.
-
-(set-struct-vtable-name! <fid> 'fid)
-
-;; (define-inlinable (%fid-printer x port)
-;;   (format port "[0x~x:0x~x:0x~x]" (fid-seq x) (fid-oid x) (fid-ver x)))
-;;
-;; (struct-set! <fid> vtable-index-printer %fid-printer)
-
-(define-inlinable (%c-style-string->number s)
-    (cond
-     ((string-prefix? "0x" s)
-      (string->number (substring s 2) 16))
-     ((string-prefix? "0" s)
-      (string->number s 8))
-     (else
-      (string->number s 10))))
-
-(define (fid? x)
-  (and (struct? x)
-       (eq? (struct-vtable x) <fid>)))
-
-(define (fid=? x1 x2)
-  (and (= (fid-seq x1) (fid-seq x2))
-       (= (fid-oid x1) (fid-oid x2))
-       (= (fid-ver x1) (fid-ver x2))))
-
-(define (fid->string x)
-  (%fid-printer x #f))
-
-(define (string->fid s)
-  (apply make-fid
-        (map %c-style-string->number
-             (string-split (string-trim-right (string-trim s #\[)
-                                              #\])
-                           #\:))))
-
-;; xattrs
-
-(define (xattr-ref-string name)
-  (utf8->string (or (xattr-ref name) #vu8())))
index 29b3edb..32ebfd2 100644 (file)
@@ -28,6 +28,7 @@
 #include "ls3_object_attrs.h"
 #include "ls3_scan.h"
 
+#define LS3_MODULE_NAME "lipe"
 #define LS3_SCAN "lipe-scan"
 #define LS3_PRINT_FILE_FID "print-file-fid"
 #define LS3_PRINT_SELF_FID "print-self-fid"
@@ -193,7 +194,7 @@ static const char *print_delim = "\n";
 static bool print_null_delim;
 static bool print_all_paths;
 
-#define X(s) SCM_GLOBAL_VARIABLE_INIT(ls3_ ## s, #s, scm_from_ulong(s))
+#define X(s) SCM_VARIABLE_INIT(ls3_ ## s, #s, scm_from_ulong(s))
 X(LS3_OBJECT_ATTR_BASE);
 X(LS3_OBJECT_ATTR_FILE_FID);
 X(LS3_OBJECT_ATTR_FILTER_FID);
@@ -214,7 +215,7 @@ SCM_GLOBAL_SYMBOL(ls3_sym_read_attr_error, "*lipe-read-attr-error*");
 SCM_GLOBAL_SYMBOL(ls3_sym_scan_break, "*lipe-scan-break*");
 SCM_GLOBAL_SYMBOL(ls3_sym_scan_continue, "*lipe-scan-continue*");
 
-SCM_GLOBAL_VARIABLE_INIT(ls3_scm_fid_vtable_var, "<fid>", ls3_scm_fid_vtable);
+SCM_VARIABLE_INIT(ls3_scm_fid_vtable_var, "<fid>", ls3_scm_fid_vtable);
 
 #define LS3_SCM_FID(fid)                       \
        ((struct lu_fid *)SCM_STRUCT_DATA(fid))
@@ -244,15 +245,6 @@ static SCM ls3_scm_from_fid(const struct lu_fid *c_fid)
        return fid;
 }
 
-#if 0
-static void ls3_scm_to_fid(SCM fid, struct lu_fid *c_fid)
-#define FUNC_NAME "ls3_scm_to_fid"
-{
-       *c_fid = *LS3_SCM_UNPACK_FID(1, fid);
-}
-#undef FUNC_NAME
-#endif
-
 static SCM ls3_scm_fid_printer(SCM x, SCM port)
 #define FUNC_NAME "ls3_fid_printer"
 {
@@ -309,7 +301,7 @@ SCM_DEFINE(ls3_scm_make_fid, "make-fid", 3, 0, 0, (SCM seq, SCM oid, SCM ver), "
 }
 #undef FUNC_NAME
 
-SCM_GLOBAL_VARIABLE_INIT(ls3_FNM_CASEFOLD, "FNM_CASEFOLD", scm_from_int(FNM_CASEFOLD));
+SCM_VARIABLE_INIT(ls3_FNM_CASEFOLD, "FNM_CASEFOLD", scm_from_int(FNM_CASEFOLD));
 
 SCM_DEFINE(ls3_scm_fnmatch_p, "fnmatch?", 2, 1, 0,
           (SCM pattern, SCM string, SCM flags), "match filename or pathname")
@@ -808,89 +800,6 @@ SCM_DEFINE(ls3_scm_print_relative_path, LS3_PRINT_RELATIVE_PATH, 0, 0, 0,
        return SCM_UNSPECIFIED;
 }
 
-#if 0
-SCM_GLOBAL_VARIABLE_INIT(ls3_scm_rmfid_max_fids, "%RMFID-MAX-FIDS",
-                        scm_from_ulong(OBD_MAX_FIDS_IN_ARRAY));
-
-SCM_DEFINE(ls3_scm_rmfid, "%rmfid", 1, 2, 0,
-          (SCM vec, SCM start, SCM end), "remove a vector of FIDs")
-#define FUNC_NAME s_ls3_scm_rmfid
-{
-       SCM res[2] = { SCM_UNDEFINED, SCM_UNDEFINED };
-       SCM bv = SCM_UNDEFINED;
-       struct fid_array *fa = NULL;
-       size_t c_len;
-       size_t c_start;
-       size_t c_end;
-       size_t c_count;
-       size_t fa_size;
-       size_t i;
-       int rc;
-
-       // Validate ls3_client_mount_fd
-       SCM_VALIDATE_VECTOR(1, vec);
-
-       c_len = scm_c_vector_length(vec);
-
-       if (SCM_UNBNDP(start))
-               c_start = 0;
-       else
-               c_start = scm_to_unsigned_integer(start, 0, c_len);
-
-       if (SCM_UNBNDP(end))
-               c_end = c_len;
-       else
-               c_end = scm_to_unsigned_integer(end, c_start, c_len);
-
-       c_count = c_end - c_start;
-
-       SCM_ASSERT_RANGE(1, scm_from_size_t(c_count), c_count <= OBD_MAX_FIDS_IN_ARRAY);
-
-       fa_size = offsetof(struct fid_array, fa_fids[c_count]);
-       LS3_DEBUG_U(c_len);
-       LS3_DEBUG_U(c_start);
-       LS3_DEBUG_U(c_end);
-       LS3_DEBUG_U(c_count);
-       LS3_DEBUG_U(fa_size);
-
-       bv = scm_c_make_bytevector(fa_size);
-       fa = (struct fid_array *)SCM_BYTEVECTOR_CONTENTS(bv);
-       memset(fa, 0, fa_size);
-
-       for (i = c_start; i < c_end; i++) {
-               ls3_scm_to_fid(scm_c_vector_ref(vec, i),
-                              &fa->fa_fids[fa->fa_nr]);
-               fa->fa_nr++;
-       }
-
-       assert(fa->fa_nr == c_count);
-
-       rc = ioctl(ls3_client_mount_fd, LL_IOC_RMFID, fa);
-       if (rc < 0) {
-               res[0] = SCM_UNSPECIFIED;
-               res[1] = scm_from_int(errno);
-               return scm_c_values(res, ARRAY_SIZE(res));
-       }
-       LS3_DEBUG_D(rc);
-
-       res[0] = scm_c_make_vector(fa->fa_nr, SCM_UNDEFINED);
-       res[1] = scm_from_int(0);
-
-       for (i = 0; i < fa->fa_nr; i++) {
-               struct lu_fid *fid = &fa->fa_fids[i];
-               __s32 rc2 = fid->f_ver;
-
-               fid->f_ver = 0;
-               SCM_SIMPLE_VECTOR_SET(res[0], i,
-                                     scm_cons(ls3_scm_from_fid(fid),
-                                              scm_from_int(-rc2)));
-       }
-
-       return scm_c_values(res, ARRAY_SIZE(res));
-}
-#undef FUNC_NAME
-#endif
-
 SCM_DEFINE(ls3_scm_scan, LS3_SCAN, 5, 0, 0,
           (SCM s_device_path,
            SCM s_client_mount_path,
@@ -1070,18 +979,8 @@ static int ls3_scm_to_exit_status(SCM rc)
        return scm_is_true(rc) ? EXIT_SUCCESS : EXIT_FAILURE;
 }
 
-static void ls3_main_scm(void *data, int argc, char *argv[])
+static void ls3_scm_init(void *unused)
 {
-       bool interactive = false;
-       const char *load_file;
-       const char *script_file = NULL;
-       const char *policy = NULL;
-       char *end;
-       int rc;
-       int c;
-
-       ls3_tid = syscall(SYS_gettid);
-
        /* Need scm_c_eval_string("#t") here to prevent.
         * Backtrace:
         * In ice-9/boot-9.scm:
@@ -1108,11 +1007,78 @@ static void ls3_main_scm(void *data, int argc, char *argv[])
                1, 0, 1,
                &ls3_policy_exception_handler);
 
-       /* Define our primitives before loading any files. */
 #ifndef SCM_MAGIC_SNARFER
 # include "ls3_main.x"
 #endif
 
+       scm_c_export(
+       "FNM_CASEFOLD",
+       "fnmatch?",
+       "<fid>",
+       "fid-seq",
+       "fid-oid",
+       "fid-ver",
+       "make-fid",
+       "lipe-debug-enable",
+       "lipe-gettid",
+       "lipe-getopt-client-mount-path",
+       "lipe-getopt-device-path",
+       "lipe-getopt-required-attrs",
+       "lipe-getopt-thread-count",
+       "lipe-scan",
+       "lipe-scan-break",
+       "lipe-scan-client-mount-fd",
+       "lipe-scan-client-mount-path",
+       "lipe-scan-continue",
+       "lipe-scan-current-attrs",
+       "lipe-scan-device-name",
+       "lipe-scan-device-path",
+       "lipe-scan-fsname",
+       "lipe-scan-thread-count",
+       "lipe-scan-thread-index",
+       "atime",
+       "blocks",
+       "ctime",
+       "flags",
+       "gid",
+       "ino",
+       "mode",
+       "mtime",
+       "nlink",
+       "projid",
+       "size",
+       "uid",
+       "file-fid",
+       "self-fid",
+       "links",
+       "absolute-paths",
+       "relative-paths",
+       "xattrs",
+       "xattr-ref",
+       "pools",
+       "print-json",
+       "print-file-fid",
+       "print-self-fid",
+       "print-absolute-path",
+       "print-relative-path",
+       NULL);
+}
+
+static void ls3_main_scm(void *data, int argc, char *argv[])
+{
+       bool interactive = false;
+       const char *load_file;
+       const char *script_file = NULL;
+       const char *policy = NULL;
+       char *end;
+       int rc;
+       int c;
+
+       ls3_tid = syscall(SYS_gettid);
+
+       /* Define our primitives before loading any files. */
+       scm_c_define_module(LS3_MODULE_NAME, &ls3_scm_init, NULL);
+
        while ((c = getopt_long(argc, argv, "hil:s:v", options, NULL)) != EOF) {
                switch (c) {
                case LS3_OPT_ALL_PATHS:
@@ -1223,7 +1189,7 @@ static void ls3_main_scm(void *data, int argc, char *argv[])
                        ls3_device_path = argv[i];
                        LS3_DEBUG_S(ls3_device_path);
 
-#define X(s) scm_variable_ref(scm_c_lookup(s))
+#define X(s) scm_c_public_ref(LS3_MODULE_NAME, s)
                        scan_rc = ls3_scm_scan(scm_call_0(X(LS3_GETOPT_DEVICE_PATH)),
                                               scm_call_0(X(LS3_GETOPT_CLIENT_MOUNT_PATH)),
                                               X(policy),
@@ -1238,6 +1204,8 @@ static void ls3_main_scm(void *data, int argc, char *argv[])
        } else {
                SCM script_rc;
 
+               scm_c_use_module(LS3_MODULE_NAME);
+
                /* Forward positional parameters to script. */
                scm_set_program_arguments(-1, argv + optind, (char *)script_file);
                script_rc = scm_c_primitive_load(script_file);
index cf0f32f..feab29c 100755 (executable)
@@ -3,7 +3,5 @@
 # This exists just to make '#!/usr/bin/env lipe_scan3_script'
 # work. With coreutils 8.30 we can use the -S, --split-string option
 # to /usr/bin/env.
-#
-# FIXME load lipe_scan_functions.scm here (or in ls3_main.c).
 
 exec lipe_scan3 --script "$@"
index c96ab25..3488754 100644 (file)
@@ -1,4 +1,4 @@
-(import (rnrs base (6))) ;; assert
+(use-modules (rnrs base)) ;; assert
 
 (assert #t)
 (assert #f)
index b995bc5..971a3af 100644 (file)
@@ -1,4 +1,6 @@
-(import (rnrs base (6))) ;; assert
+(use-modules (rnrs base) ;; assert
+            (lipe)
+            (lipe fid))
 
 (define root-fid-string "[0x200000007:0x1:0x0]")
 (define root-fid-seq #x200000007)
@@ -24,8 +26,6 @@
 (newline)
 (display root-fid)
 (newline)
-(%fid-printer root-fid #t)
-(newline)
 (format #t "~a\n" root-fid)
 (format #f "~a\n" root-fid)
 (format (current-error-port) "~a\n" root-fid)
index 57c7fb4..e56e3e1 100644 (file)
@@ -1,4 +1,4 @@
-(import (rnrs base (6))) ;; assert
+(use-modules (rnrs base)) ;; assert
 
 (assert (procedure? fnmatch?))
 (assert (integer? FNM_CASEFOLD))
index 4ec62c8..78f1bb6 100644 (file)
@@ -1,4 +1,4 @@
-(import (rnrs base (6))) ;; assert
+(use-modules (rnrs base)) ;; assert
 
 (assert (procedure? lipe-debug-enable))
 (assert (eq? #f (lipe-debug-enable)))
index 61a7248..86fddbc 100644 (file)
@@ -1,4 +1,3 @@
-
 #!/bin/bash
 #
 # Tests for lipe_find and lipe_scan.