X-Git-Url: http://git.annexia.org/?a=blobdiff_plain;ds=inline;f=src%2Fgenerator.ml;h=b6f6f42a20ee7d709009c557271958f4ede49398;hb=58e7e42033b1ac5044ae03f0aa5d5082c5fdb497;hp=b0b3f066f46f538e04dd440a511acab3bb2d3015;hpb=77b2275dfcebce16ceea17ddf77a7f9d0a41c082;p=libguestfs.git diff --git a/src/generator.ml b/src/generator.ml index b0b3f06..b6f6f42 100755 --- a/src/generator.ml +++ b/src/generator.ml @@ -3295,6 +3295,104 @@ Create a swap file. This command just writes a swap file signature to an existing file. To create the file itself, use something like C."); + ("inotify_init", (RErr, [Int "maxevents"]), 179, [], + [InitSquashFS, Always, TestRun ( + [["inotify_init"; "0"]])], + "create an inotify handle", + "\ +This command creates a new inotify handle. +The inotify subsystem can be used to notify events which happen to +objects in the guest filesystem. + +C is the maximum number of events which will be +queued up between calls to C or +C. +If this is passed as C<0>, then the kernel (or previously set) +default is used. For Linux 2.6.29 the default was 16384 events. +Beyond this limit, the kernel throws away events, but records +the fact that it threw them away by setting a flag +C in the returned structure list (see +C). + +Before any events are generated, you have to add some +watches to the internal watch list. See: +C, +C and +C. + +Queued up events should be read periodically by calling +C +(or C which is just a helpful +wrapper around C). If you don't +read the events out often enough then you risk the internal +queue overflowing. + +The handle should be closed after use by calling +C. This also removes any +watches automatically. + +See also L for an overview of the inotify interface +as exposed by the Linux kernel, which is roughly what we expose +via libguestfs. Note that there is one global inotify handle +per libguestfs instance."); + + ("inotify_add_watch", (RInt64 "wd", [String "path"; Int "mask"]), 180, [], + [InitBasicFS, Always, TestOutputList ( + [["inotify_init"; "0"]; + ["inotify_add_watch"; "/"; "1073741823"]; + ["touch"; "/a"]; + ["touch"; "/b"]; + ["inotify_files"]], ["a"; "b"])], + "add an inotify watch", + "\ +Watch C for the events listed in C. + +Note that if C is a directory then events within that +directory are watched, but this does I happen recursively +(in subdirectories). + +Note for non-C or non-Linux callers: the inotify events are +defined by the Linux kernel ABI and are listed in +C."); + + ("inotify_rm_watch", (RErr, [Int(*XXX64*) "wd"]), 181, [], + [], + "remove an inotify watch", + "\ +Remove a previously defined inotify watch. +See C."); + + ("inotify_read", (RStructList ("events", "inotify_event"), []), 182, [], + [], + "return list of inotify events", + "\ +Return the complete queue of events that have happened +since the previous read call. + +If no events have happened, this returns an empty list. + +I: In order to make sure that all events have been +read, you must call this function repeatedly until it +returns an empty list. The reason is that the call will +read events up to the maximum appliance-to-host message +size and leave remaining events in the queue."); + + ("inotify_files", (RStringList "paths", []), 183, [], + [], + "return list of watched files that had events", + "\ +This function is a helpful wrapper around C +which just returns a list of pathnames of objects that were +touched. The returned pathnames are sorted and deduplicated."); + + ("inotify_close", (RErr, []), 184, [], + [], + "close the inotify handle", + "\ +This closes the inotify handle which was previously +opened by inotify_init. It removes all watches, throws +away any pending events, and deallocates all resources."); + ] let all_functions = non_daemon_functions @ daemon_functions @@ -3309,7 +3407,7 @@ let all_functions_sorted = (* Field types for structures. *) type field = | FChar (* C 'char' (really, a 7 bit byte). *) - | FString (* nul-terminated ASCII string. *) + | FString (* nul-terminated ASCII string, NOT NULL. *) | FBuffer (* opaque buffer of bytes, (char *, int) pair *) | FUInt32 | FInt32 @@ -3455,6 +3553,14 @@ let structs = [ "attrname", FString; "attrval", FBuffer; ]; + + (* Inotify events. *) + "inotify_event", [ + "in_wd", FInt64; + "in_mask", FUInt32; + "in_cookie", FUInt32; + "in_name", FString; + ]; ] (* end of structs *) (* Ugh, Java has to be different .. @@ -3470,6 +3576,7 @@ let java_structs = [ "dirent", "Dirent"; "version", "Version"; "xattr", "XAttr"; + "inotify_event", "INotifyEvent"; ] (* Used for testing language bindings. *) @@ -3581,6 +3688,13 @@ let files_equal n1 n2 = | 1 -> false | i -> failwithf "%s: failed with error code %d" cmd i +let rec filter_map f = function + | [] -> [] + | x :: xs -> + match f x with + | Some y -> y :: filter_map f xs + | None -> filter_map f xs + let rec find_map f = function | [] -> raise Not_found | x :: xs -> @@ -4923,15 +5037,29 @@ static void print_table (char * const * const argv) } */ -static void no_test_warnings (void) -{ "; + (* Generate a list of commands which are not tested anywhere. *) + pr "static void no_test_warnings (void)\n"; + pr "{\n"; + + let hash : (string, bool) Hashtbl.t = Hashtbl.create 13 in List.iter ( - function - | name, _, _, _, [], _, _ -> + fun (_, _, _, _, tests, _, _) -> + let tests = filter_map ( + function + | (_, (Always|If _|Unless _), test) -> Some test + | (_, Disabled, _) -> None + ) tests in + let seq = List.concat (List.map seq_of_test tests) in + let cmds_tested = List.map List.hd seq in + List.iter (fun cmd -> Hashtbl.replace hash cmd true) cmds_tested + ) all_functions; + + List.iter ( + fun (name, _, _, _, _, _, _) -> + if not (Hashtbl.mem hash name) then pr " fprintf (stderr, \"warning: \\\"guestfs_%s\\\" has no tests\\n\");\n" name - | name, _, _, _, tests, _, _ -> () ) all_functions; pr "}\n"; @@ -5674,7 +5802,7 @@ and generate_fish_cmds () = let needs_i = List.exists (function (_, (FUUID|FBuffer)) -> true | _ -> false) cols in - pr "static void print_%s (struct guestfs_%s *%s)\n" typ typ typ; + pr "static void print_%s_indent (struct guestfs_%s *%s, const char *indent)\n" typ typ typ; pr "{\n"; if needs_i then ( pr " int i;\n"; @@ -5683,44 +5811,57 @@ and generate_fish_cmds () = List.iter ( function | name, FString -> - pr " printf (\"%s: %%s\\n\", %s->%s);\n" name typ name + pr " printf (\"%%s%s: %%s\\n\", indent, %s->%s);\n" name typ name | name, FUUID -> pr " printf (\"%s: \");\n" name; pr " for (i = 0; i < 32; ++i)\n"; - pr " printf (\"%%c\", %s->%s[i]);\n" typ name; + pr " printf (\"%%s%%c\", indent, %s->%s[i]);\n" typ name; pr " printf (\"\\n\");\n" | name, FBuffer -> - pr " printf (\"%s: \");\n" name; + pr " printf (\"%%s%s: \", indent);\n" name; pr " for (i = 0; i < %s->%s_len; ++i)\n" typ name; pr " if (isprint (%s->%s[i]))\n" typ name; - pr " printf (\"%%c\", %s->%s[i]);\n" typ name; + pr " printf (\"%%s%%c\", indent, %s->%s[i]);\n" typ name; pr " else\n"; - pr " printf (\"\\\\x%%02x\", %s->%s[i]);\n" typ name; + pr " printf (\"%%s\\\\x%%02x\", indent, %s->%s[i]);\n" typ name; pr " printf (\"\\n\");\n" | name, (FUInt64|FBytes) -> - pr " printf (\"%s: %%\" PRIu64 \"\\n\", %s->%s);\n" name typ name + pr " printf (\"%%s%s: %%\" PRIu64 \"\\n\", indent, %s->%s);\n" + name typ name | name, FInt64 -> - pr " printf (\"%s: %%\" PRIi64 \"\\n\", %s->%s);\n" name typ name + pr " printf (\"%%s%s: %%\" PRIi64 \"\\n\", indent, %s->%s);\n" + name typ name | name, FUInt32 -> - pr " printf (\"%s: %%\" PRIu32 \"\\n\", %s->%s);\n" name typ name + pr " printf (\"%%s%s: %%\" PRIu32 \"\\n\", indent, %s->%s);\n" + name typ name | name, FInt32 -> - pr " printf (\"%s: %%\" PRIi32 \"\\n\", %s->%s);\n" name typ name + pr " printf (\"%%s%s: %%\" PRIi32 \"\\n\", indent, %s->%s);\n" + name typ name | name, FChar -> - pr " printf (\"%s: %%c\\n\", %s->%s);\n" name typ name + pr " printf (\"%%s%s: %%c\\n\", indent, %s->%s);\n" + name typ name | name, FOptPercent -> - pr " if (%s->%s >= 0) printf (\"%s: %%g %%%%\\n\", %s->%s);\n" + pr " if (%s->%s >= 0) printf (\"%%s%s: %%g %%%%\\n\", indent, %s->%s);\n" typ name name typ name; - pr " else printf (\"%s: \\n\");\n" name + pr " else printf (\"%%s%s: \\n\", indent);\n" name ) cols; pr "}\n"; pr "\n"; + pr "static void print_%s (struct guestfs_%s *%s)\n" typ typ typ; + pr "{\n"; + pr " print_%s_indent (%s, \"\");\n" typ typ; + pr "}\n"; + pr "\n"; pr "static void print_%s_list (struct guestfs_%s_list *%ss)\n" typ typ typ; pr "{\n"; pr " int i;\n"; pr "\n"; - pr " for (i = 0; i < %ss->len; ++i)\n" typ; - pr " print_%s (&%ss->val[i]);\n" typ typ; + pr " for (i = 0; i < %ss->len; ++i) {\n" typ; + pr " printf (\"[%%d] = {\\n\", i);\n"; + pr " print_%s_indent (&%ss->val[i], \" \");\n" typ typ; + pr " printf (\"}\\n\");\n"; + pr " }\n"; pr "}\n"; pr "\n"; ) structs;