[PATCH] appliance: init: properly set PS1 and TERM for virt-rescue (RHBZ#812970).
by Pino Toscano
Setting environment variables such as PS1 for bash before starting it
might not be effective when the startup scripts provided by the
distribution unconditionally change it.
Hence, set PS1 and TERM in a ~/.bashrc, which will be source'd last and
thus be able to set them the way we want.
---
appliance/init | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/appliance/init b/appliance/init
index 8d13f2c..b407bf9 100755
--- a/appliance/init
+++ b/appliance/init
@@ -142,9 +142,10 @@ else
# Remove LD_PRELOAD=libSegFault set above.
unset LD_PRELOAD
- eval $(grep -Eo 'TERM=[^[:space:]]+' /proc/cmdline)
- PS1='><rescue> '
- export TERM PS1
+ :> $HOME/.bashrc
+ grep -Eo 'TERM=[^[:space:]]+' /proc/cmdline >> $HOME/.bashrc
+ echo "PS1='><rescue> '" >> $HOME/.bashrc
+ echo "export TERM PS1" >> $HOME/.bashrc
echo
echo "------------------------------------------------------------"
--
1.9.3
10 years, 5 months
[PATCH] daemon: grub: show grub-install's output on error if verbose
by Pino Toscano
---
daemon/grub.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/daemon/grub.c b/daemon/grub.c
index c058599..9596d7a 100644
--- a/daemon/grub.c
+++ b/daemon/grub.c
@@ -38,16 +38,19 @@ int
do_grub_install (const char *root, const char *device)
{
int r;
- CLEANUP_FREE char *err = NULL, *buf = NULL;
+ CLEANUP_FREE char *err = NULL, *buf = NULL, *out = NULL;
if (asprintf_nowarn (&buf, "--root-directory=%R", root) == -1) {
reply_with_perror ("asprintf");
return -1;
}
- r = command (NULL, &err, str_grub_install, buf, device, NULL);
+ r = command (verbose ? &out : NULL, &err,
+ str_grub_install, buf, device, NULL);
if (r == -1) {
+ if (verbose)
+ fprintf (stderr, "grub output:\n%s\n", out);
reply_with_error ("%s", err);
return -1;
}
--
1.9.3
10 years, 5 months
[PATCH] daemon: print parameters for vgchange in error messages
by Pino Toscano
---
daemon/lvm-filter.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/daemon/lvm-filter.c b/daemon/lvm-filter.c
index ed10a48..6976bab 100644
--- a/daemon/lvm-filter.c
+++ b/daemon/lvm-filter.c
@@ -200,7 +200,7 @@ vgchange (const char *vgchange_flag)
CLEANUP_FREE char *err = NULL;
int r = command (NULL, &err, str_lvm, "vgchange", vgchange_flag, NULL);
if (r == -1) {
- reply_with_error ("vgchange: %s", err);
+ reply_with_error ("vgchange %s: %s", vgchange_flag, err);
return -1;
}
--
1.9.3
10 years, 5 months
[PATCH] daemon: retire the augeas feature
by Pino Toscano
Augeas has been a mandatory dependency of libguestfs for quite some
time, so the aug_* functions could have been always called (without even
checking the augeas feature). Thus retire the feature, marking it as
always available with no more functions depending on it.
---
daemon/augeas.c | 6 ------
generator/actions.ml | 16 ----------------
generator/optgroups.ml | 1 +
3 files changed, 1 insertion(+), 22 deletions(-)
diff --git a/daemon/augeas.c b/daemon/augeas.c
index 04faac9..e31cab4 100644
--- a/daemon/augeas.c
+++ b/daemon/augeas.c
@@ -29,12 +29,6 @@
#include "actions.h"
#include "optgroups.h"
-int
-optgroup_augeas_available (void)
-{
- return 1;
-}
-
/* The Augeas handle. We maintain a single handle per daemon, which
* is all that is necessary and reduces the complexity of the API
* considerably.
diff --git a/generator/actions.ml b/generator/actions.ml
index ed65c6e..3bd41f0 100644
--- a/generator/actions.ml
+++ b/generator/actions.ml
@@ -3472,7 +3472,6 @@ of the L<lvs(8)> command. The \"full\" version includes all fields." };
name = "aug_init";
style = RErr, [Pathname "root"; Int "flags"], [];
proc_nr = Some 16;
- optional = Some "augeas";
tests = [
InitBasicFS, Always, TestResultString (
[["mkdir"; "/etc"];
@@ -3538,7 +3537,6 @@ To find out more about Augeas, see L<http://augeas.net/>." };
name = "aug_close";
style = RErr, [], [];
proc_nr = Some 26;
- optional = Some "augeas";
shortdesc = "close the current Augeas handle";
longdesc = "\
Close the current Augeas handle and free up any resources
@@ -3550,7 +3548,6 @@ Augeas functions." };
name = "aug_defvar";
style = RInt "nrnodes", [String "name"; OptString "expr"], [];
proc_nr = Some 17;
- optional = Some "augeas";
shortdesc = "define an Augeas variable";
longdesc = "\
Defines an Augeas variable C<name> whose value is the result
@@ -3564,7 +3561,6 @@ C<0> if C<expr> evaluates to something which is not a nodeset." };
name = "aug_defnode";
style = RStruct ("nrnodescreated", "int_bool"), [String "name"; String "expr"; String "val"], [];
proc_nr = Some 18;
- optional = Some "augeas";
shortdesc = "define an Augeas node";
longdesc = "\
Defines a variable C<name> whose value is the result of
@@ -3582,7 +3578,6 @@ if a node was created." };
name = "aug_get";
style = RString "val", [String "augpath"], [];
proc_nr = Some 19;
- optional = Some "augeas";
shortdesc = "look up the value of an Augeas path";
longdesc = "\
Look up the value associated with C<path>. If C<path>
@@ -3592,7 +3587,6 @@ matches exactly one node, the C<value> is returned." };
name = "aug_set";
style = RErr, [String "augpath"; String "val"], [];
proc_nr = Some 20;
- optional = Some "augeas";
tests = [
InitBasicFS, Always, TestResultString (
[["mkdir"; "/etc"];
@@ -3614,7 +3608,6 @@ C<guestfs_aug_clear> call." };
name = "aug_insert";
style = RErr, [String "augpath"; String "label"; Bool "before"], [];
proc_nr = Some 21;
- optional = Some "augeas";
tests = [
InitBasicFS, Always, TestResultString (
[["mkdir"; "/etc"];
@@ -3642,7 +3635,6 @@ with a bracketed index C<[N]>." };
name = "aug_rm";
style = RInt "nrnodes", [String "augpath"], [];
proc_nr = Some 22;
- optional = Some "augeas";
shortdesc = "remove an Augeas path";
longdesc = "\
Remove C<path> and all of its children.
@@ -3653,7 +3645,6 @@ On success this returns the number of entries which were removed." };
name = "aug_mv";
style = RErr, [String "src"; String "dest"], [];
proc_nr = Some 23;
- optional = Some "augeas";
shortdesc = "move Augeas node";
longdesc = "\
Move the node C<src> to C<dest>. C<src> must match exactly
@@ -3663,7 +3654,6 @@ one node. C<dest> is overwritten if it exists." };
name = "aug_match";
style = RStringList "matches", [String "augpath"], [];
proc_nr = Some 24;
- optional = Some "augeas";
shortdesc = "return Augeas nodes which match augpath";
longdesc = "\
Returns a list of paths which match the path expression C<path>.
@@ -3674,7 +3664,6 @@ exactly one node in the current tree." };
name = "aug_save";
style = RErr, [], [];
proc_nr = Some 25;
- optional = Some "augeas";
shortdesc = "write all pending Augeas changes to disk";
longdesc = "\
This writes all pending changes to disk.
@@ -3686,7 +3675,6 @@ how files are saved." };
name = "aug_load";
style = RErr, [], [];
proc_nr = Some 27;
- optional = Some "augeas";
shortdesc = "load files into the tree";
longdesc = "\
Load files into the tree.
@@ -3698,7 +3686,6 @@ details." };
name = "aug_ls";
style = RStringList "matches", [String "augpath"], [];
proc_nr = Some 28;
- optional = Some "augeas";
tests = [
InitBasicFS, Always, TestResult (
[["mkdir"; "/etc"];
@@ -8252,7 +8239,6 @@ group." };
name = "aug_clear";
style = RErr, [String "augpath"], [];
proc_nr = Some 239;
- optional = Some "augeas";
shortdesc = "clear Augeas path";
longdesc = "\
Set the value associated with C<path> to C<NULL>. This
@@ -11757,7 +11743,6 @@ See also C<guestfs_journal_get_data_threshold>." };
name = "aug_setm";
style = RInt "nodes", [String "base"; OptString "sub"; String "val"], [];
proc_nr = Some 411;
- optional = Some "augeas";
tests = [
InitBasicFS, Always, TestResultString (
[["mkdir"; "/etc"];
@@ -11781,7 +11766,6 @@ This returns the number of nodes modified." };
name = "aug_label";
style = RString "label", [String "augpath"], [];
proc_nr = Some 412;
- optional = Some "augeas";
tests = [
InitBasicFS, Always, TestResultString (
[["mkdir"; "/etc"];
diff --git a/generator/optgroups.ml b/generator/optgroups.ml
index d13d794..1c5bd91 100644
--- a/generator/optgroups.ml
+++ b/generator/optgroups.ml
@@ -27,6 +27,7 @@ open Actions
* list of functions.
*)
let optgroups_retired = [
+ "augeas";
"realpath";
]
--
1.9.3
10 years, 5 months
[PATCH] builder: handle duplicated images (RHBZ#1092753).
by Pino Toscano
Filter the available images, removing the versions with an older
revisions, and duplicates.
---
builder/builder.ml | 36 ++++++++++++++++++++++++++++++++++++
1 file changed, 36 insertions(+)
diff --git a/builder/builder.ml b/builder/builder.ml
index 2884cf6..5c2f6bb 100644
--- a/builder/builder.ml
+++ b/builder/builder.ml
@@ -36,6 +36,41 @@ let prog = Filename.basename Sys.executable_name
let () = Random.self_init ()
+let remove_duplicates index =
+ (* Fill an hash with the higher revision of the available
+ * (name, arch) tuples, so it possible to ignore duplicates,
+ * and versions with a lower revision.
+ *)
+ let nseen = Hashtbl.create 13 in
+ List.iter (
+ fun (name, { Index_parser.arch = arch; revision = revision }) ->
+ let id = name, arch in
+ try
+ let rev = Hashtbl.find nseen id in
+ if revision > rev then
+ Hashtbl.replace nseen id revision
+ with Not_found ->
+ Hashtbl.add nseen id revision
+ ) index;
+ List.filter (
+ fun (name, { Index_parser.arch = arch; revision = revision }) ->
+ let id = name, arch in
+ try
+ let rev = Hashtbl.find nseen (name, arch) in
+ (* Take the first occurrency with the higher revision,
+ * removing it from the hash so the other occurrencies
+ * are ignored.
+ *)
+ if revision = rev then (
+ Hashtbl.remove nseen id;
+ true
+ ) else
+ false
+ with Not_found ->
+ (* Already taken, so ignore. *)
+ false
+ ) index
+
let main () =
(* Command line argument parsing - see cmdline.ml. *)
let mode, arg,
@@ -146,6 +181,7 @@ let main () =
Index_parser.get_index ~prog ~debug ~downloader ~sigchecker ~proxy source
) sources
) in
+ let index = remove_duplicates index in
(* Now handle the remaining modes. *)
let mode =
--
1.9.3
10 years, 5 months
[PATCH] inspect: tighten NetBSD detection
by Pino Toscano
It seems recent (?) NetBSD versions have their kernel as /netbsd, so
also check for it to detect NetBSD installations.
The current detection so far basically relied on generic files and
directories which can potentially be in every UNIX system, misdetecting
them if a /etc/release file is present in them.
---
src/inspect-fs.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/src/inspect-fs.c b/src/inspect-fs.c
index c011b5a..21d2a23 100644
--- a/src/inspect-fs.c
+++ b/src/inspect-fs.c
@@ -222,6 +222,7 @@ check_filesystem (guestfs_h *g, const char *mountable,
}
else if (is_dir_etc &&
is_dir_bin &&
+ guestfs_is_file (g, "/netbsd") > 0 &&
guestfs_is_file (g, "/etc/fstab") > 0 &&
guestfs_is_file (g, "/etc/release") > 0) {
/* Ignore /dev/sda1 which is a shadow of the real root filesystem
--
1.9.3
10 years, 5 months
[PATCH] fish: list also aliases in the guestfish help (RHBZ#1103877).
by Pino Toscano
Output also the aliases (telling which function they refer to) in
`guestfish -h`, together with non-alias functions.
---
generator/fish.ml | 38 ++++++++++++++++++++++++++++++++++----
1 file changed, 34 insertions(+), 4 deletions(-)
diff --git a/generator/fish.ml b/generator/fish.ml
index db800ef..3f53ffa 100644
--- a/generator/fish.ml
+++ b/generator/fish.ml
@@ -31,6 +31,14 @@ open Prepopts
open C
open Events
+type func =
+ | Function of string (* The description. *)
+ | Alias of string (* The function of which it is one the
+ * aliases.
+ *)
+
+let func_compare (n1, _) (n2, _) = compare n1 n2
+
let fish_functions_and_commands_sorted =
List.sort action_compare (fish_functions_sorted @ fish_commands)
@@ -46,6 +54,21 @@ let get_aliases { fish_alias = fish_alias; non_c_aliases = non_c_aliases } =
List.map (fun n -> replace_char n '_' '-') non_c_aliases in
fish_alias @ non_c_aliases
+let all_functions_commands_and_aliases_sorted =
+ let all =
+ List.fold_right (
+ fun ({ name = name; shortdesc = shortdesc } as f) acc ->
+ let aliases = get_aliases f in
+ let aliases = List.filter (
+ fun x ->
+ Filename.check_suffix x "-opts" <> true
+ ) aliases in
+ let aliases = List.map (fun x -> x, Alias name) aliases in
+ let foo = (name, Function shortdesc) :: aliases in
+ foo @ acc
+ ) (fish_functions_sorted @ fish_commands) [] in
+ List.sort func_compare all
+
(* Generate a lot of different functions for guestfish. *)
let generate_fish_cmds () =
generate_header CStyle GPLv2plus;
@@ -179,11 +202,18 @@ Guestfish will prompt for these separately."
pr " printf (\" %%-16s %%s\\n\", _(\"Command\"), _(\"Description\"));\n";
pr " list_builtin_commands ();\n";
List.iter (
- fun { name = name; shortdesc = shortdesc } ->
+ fun (name, f) ->
let name = replace_char name '_' '-' in
- pr " printf (\"%%-20s %%s\\n\", \"%s\", _(\"%s\"));\n"
- name shortdesc
- ) fish_functions_and_commands_sorted;
+ match f with
+ | Function shortdesc ->
+ pr " printf (\"%%-20s %%s\\n\", \"%s\", _(\"%s\"));\n"
+ name shortdesc
+ | Alias f ->
+ let f = replace_char f '_' '-' in
+ pr " printf (\"%%-20s \", \"%s\");\n" name;
+ pr " printf (_(\"alias for '%%s'\"), \"%s\");\n" f;
+ pr " putchar ('\\n');\n"
+ ) all_functions_commands_and_aliases_sorted;
pr " printf (\" %%s\\n\",";
pr " _(\"Use -h <cmd> / help <cmd> to show detailed help for a command.\"));\n";
pr "}\n";
--
1.9.3
10 years, 5 months
Re: [Libguestfs] [openstack-dev] [Nova] nova-compute deadlock
by Richard W.M. Jones
On Sat, May 31, 2014 at 01:25:04AM +0800, Qin Zhao wrote:
> Hi all,
>
> When I run Icehouse code, I encountered a strange problem. The nova-compute
> service becomes stuck, when I boot instances. I report this bug in
> https://bugs.launchpad.net/nova/+bug/1313477.
>
> After thinking several days, I feel I know its root cause. This bug should
> be a deadlock problem cause by pipe fd leaking. I draw a diagram to
> illustrate this problem.
> https://docs.google.com/drawings/d/1pItX9urLd6fmjws3BVovXQvRg_qMdTHS-0JhY...
>
> However, I have not find a very good solution to prevent this deadlock.
> This problem is related with Python runtime, libguestfs, and eventlet. The
> situation is a little complicated. Is there any expert who can help me to
> look for a solution? I will appreciate for your help!
Thanks for the useful diagram. libguestfs itself is very careful to
open all file descriptors with O_CLOEXEC (atomically if the OS
supports that), so I'm fairly confident that the bug is in Python 2,
not in libguestfs.
Another thing to say is that g.shutdown() sends a kill 9 signal to the
subprocess. Furthermore you can obtain the qemu PID (g.get_pid()) and
send any signal you want to the process.
I wonder if a simpler way to fix this wouldn't be something like
adding a tiny C extension to the Python code to use pipe2 to open the
Python pipe with O_CLOEXEC atomically? Are we allowed Python
extensions in OpenStack?
BTW do feel free to CC libguestfs(a)redhat.com on any libguestfs
problems you have. You don't need to subscribe to the list.
Rich.
--
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
virt-p2v converts physical machines to virtual machines. Boot with a
live CD or over the network (PXE) and turn machines into KVM guests.
http://libguestfs.org/virt-v2v
10 years, 5 months
[PATCH] library: per-handle locking support
by Maros Zatko
Introduces private pool of muteces (per_handle_locks) guarded by read-write
mutex (locks_lock) using guestfs__per_handle_lock_lock(g) and
guestfs__per_handle_lock_unlock(g), where g is current valid guestfs_h handle.
Above two are used in generator/c.ml at begin and end of each non-deamon call.
New lock can be created using guestfs__per_handle_lock_add(g) and
destroyed with guestfs__per_handle_lock_remove(g). These two are called
automatically too. First one is called by guestfs_create and second by
guestfs_destroy.
---
generator/c.ml | 10 ++++
src/Makefile.am | 1 +
src/handle.c | 4 ++
src/locking.c | 162 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
src/locking.h | 45 ++++++++++++++++
5 files changed, 222 insertions(+)
create mode 100644 src/locking.c
create mode 100644 src/locking.h
diff --git a/generator/c.ml b/generator/c.ml
index ee276dc..e67053e 100644
--- a/generator/c.ml
+++ b/generator/c.ml
@@ -788,6 +788,9 @@ and generate_internal_actions_h () =
pr "#define GUESTFS_INTERNAL_ACTIONS_H_\n";
pr "\n";
+ pr "#include \"locking.h\"\n";
+ pr "\n";
+
List.iter (
fun { c_name = c_name; style = style } ->
generate_prototype ~single_line:true ~newline:true ~handle:"g"
@@ -1569,6 +1572,9 @@ and generate_client_actions hash () =
handle_null_optargs optargs c_name;
+ pr " guestfs___per_handle_lock_lock (g);\n";
+ pr "\n";
+
pr " int trace_flag = g->trace;\n";
pr " struct trace_buffer trace_buffer;\n";
(match ret with
@@ -1617,6 +1623,10 @@ and generate_client_actions hash () =
trace_return name style "r";
);
pr "\n";
+
+ pr " guestfs___per_handle_lock_unlock (g);\n";
+ pr "\n";
+
pr " return r;\n";
pr "}\n";
pr "\n"
diff --git a/src/Makefile.am b/src/Makefile.am
index 3d06203..f1f42d0 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -118,6 +118,7 @@ libguestfs_la_SOURCES = \
libvirt-auth.c \
libvirt-domain.c \
listfs.c \
+ locking.c \
lpj.c \
match.c \
osinfo.c \
diff --git a/src/handle.c b/src/handle.c
index 719bbcd..8397157 100644
--- a/src/handle.c
+++ b/src/handle.c
@@ -84,6 +84,8 @@ guestfs_create_flags (unsigned flags, ...)
g = calloc (1, sizeof (*g));
if (!g) return NULL;
+ guestfs___per_handle_lock_add (g);
+
g->state = CONFIG;
g->conn = NULL;
@@ -305,6 +307,8 @@ guestfs_close (guestfs_h *g)
return;
}
+ guestfs___per_handle_lock_remove (g);
+
/* Remove the handle from the handles list. */
if (g->close_on_exit) {
gl_lock_lock (handles_lock);
diff --git a/src/locking.c b/src/locking.c
new file mode 100644
index 0000000..2a35fce
--- /dev/null
+++ b/src/locking.c
@@ -0,0 +1,162 @@
+/* libguestfs
+ * Copyright (C) 2009-2014 Red Hat Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <config.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <errno.h>
+
+#include "glthread/lock.h"
+#include "ignore-value.h"
+
+#include "guestfs.h"
+#include "guestfs-internal.h"
+#include "guestfs-internal-actions.h"
+#include "guestfs_protocol.h"
+
+#include "locking.h"
+
+static gl_lock_t guestfs___lookup_lock_or_abort (guestfs_h *g, int *pos);
+static void guestfs___per_handle_lock_is_not_held (guestfs_h *g);
+static void ___shrink_lock_arrays (void);
+
+
+gl_lock_define (static, *per_handle_locks)
+gl_rwlock_define_initialized (static, locks_lock)
+
+/* items in handles array bijectively corresponds to items in per_handle_locks
+ */
+static guestfs_h ** handles;
+static size_t n_handles;
+
+
+static gl_lock_t
+guestfs___lookup_lock_or_abort (guestfs_h *g, int *pos)
+{
+ // this function should be called with locks_lock already held
+ for (size_t i = 0; i < n_handles; i++) {
+ if (handles[i] == g) {
+ if (pos != NULL) {
+ *pos = i;
+ }
+ return per_handle_locks[i];
+ }
+ }
+ // handle not found. aborting
+ error (g, _("guestfs lock handle not found"));
+ abort ();
+}
+
+static void
+guestfs___per_handle_lock_is_not_held (guestfs_h *g)
+{
+ // this function should be called with locks_lock already held
+
+ int i;
+ gl_lock_t l = guestfs___lookup_lock_or_abort (g, &i);
+
+ gl_lock_lock (l);
+ gl_lock_unlock (l);
+}
+
+void
+guestfs___per_handle_lock_add (guestfs_h *g)
+{
+ gl_rwlock_wrlock (locks_lock);
+
+ n_handles++;
+ per_handle_locks = realloc (per_handle_locks,
+ sizeof (*per_handle_locks) * n_handles);
+ handles = realloc (handles, sizeof (*handles) * n_handles);
+
+ gl_lock_init (per_handle_locks[n_handles - 1]);
+ handles[n_handles - 1] = g;
+
+ gl_rwlock_unlock (locks_lock);
+}
+
+static void
+___shrink_lock_arrays (void)
+{
+ // locks_lock should be held
+
+ int i;
+ guestfs___lookup_lock_or_abort (NULL, &i);
+
+ memmove (handles + i, handles + i + 1, (n_handles - i - 1)
+ * sizeof (*handles));
+ memmove (per_handle_locks + i, per_handle_locks + i + 1,
+ (n_handles - i - 1) * sizeof (*per_handle_locks));
+ if (handles == NULL || per_handle_locks == NULL) {
+ abort ();
+ }
+}
+
+void
+guestfs___per_handle_lock_remove (guestfs_h *g)
+{
+ // locks_lock prevents per_handle_locks manipulation within this module
+ // take write lock, since we're going to update guarded per_handle_locks
+ gl_rwlock_wrlock (locks_lock);
+
+ // ensure we don't get into data race when removing lock
+ guestfs___per_handle_lock_is_not_held (g);
+
+ int i;
+ gl_lock_t l = guestfs___lookup_lock_or_abort (g, &i);
+ gl_lock_destroy (l);
+ handles[i] = NULL;
+ // fill in hole we've created
+ ___shrink_lock_arrays ();
+
+ // and realloc
+ n_handles--;
+ if (n_handles > 0) {
+ per_handle_locks = realloc (per_handle_locks,
+ sizeof (*per_handle_locks) * n_handles);
+ handles = realloc (handles, sizeof (*handles) * n_handles);
+ }
+
+ gl_rwlock_unlock (locks_lock);
+}
+
+void
+guestfs___per_handle_lock_lock (guestfs_h *g)
+{
+ gl_rwlock_rdlock (locks_lock);
+
+ gl_lock_t l = guestfs___lookup_lock_or_abort(g, NULL);
+ gl_lock_lock(l);
+
+ gl_rwlock_unlock (locks_lock);
+}
+
+void
+guestfs___per_handle_lock_unlock (guestfs_h *g)
+{
+ gl_rwlock_rdlock (locks_lock);
+
+ gl_lock_t l = guestfs___lookup_lock_or_abort(g, NULL);
+ gl_lock_unlock(l);
+
+ gl_rwlock_unlock (locks_lock);
+}
+
diff --git a/src/locking.h b/src/locking.h
new file mode 100644
index 0000000..fc7bc46
--- /dev/null
+++ b/src/locking.h
@@ -0,0 +1,45 @@
+/* libguestfs
+ * Copyright (C) 2009-2014 Red Hat Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef _LOCKING_H
+#define _LOCKING_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <config.h>
+
+#include "glthread/lock.h"
+
+#include "guestfs.h"
+#include "guestfs-internal.h"
+
+extern void guestfs___per_handle_lock_add (guestfs_h *g);
+
+extern void guestfs___per_handle_lock_remove (guestfs_h *g);
+
+extern void guestfs___per_handle_lock_lock (guestfs_h *g);
+
+extern void guestfs___per_handle_lock_unlock (guestfs_h *g);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _LOCKING_H */
--
1.9.3
10 years, 5 months
libguestfs error
by abhishek jain
Hi
I'm getting following error while compiling libguestfs-1.26.1...
CCLD guestfish
guestfish-progress.o: In function `progress_bar_init':
/home/ubuntu/libguestfs-1.26.1/fish/progress.c:123: undefined reference to
`tgetent'
guestfish-progress.o: In function `progress_bar_set':
/home/ubuntu/libguestfs-1.26.1/fish/progress.c:282: undefined reference to
`tgetnum'
/home/ubuntu/libguestfs-1.26.1/fish/progress.c:297: undefined reference to
`UP'
guestfish-progress.o: In function `fprintf':
/usr/include/powerpc-linux-gnu/bits/stdio2.h:97: undefined reference to `UP'
collect2: error: ld returned 1 exit status
make[3]: *** [guestfish] Error 1
make[3]: Leaving directory `/home/ubuntu/libguestfs-1.26.1/fish'
make[2]: *** [all] Error 2
make[2]: Leaving directory `/home/ubuntu/libguestfs-1.26.1/fish'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/home/ubuntu/libguestfs-1.26.1'
make: *** [all] Error 2
I was able to compile it yesterday but when i formatted my hard disk and
tried to install it again,it started showing the above error.
Please help regarding this.
Thanks
Abhishek Jain
10 years, 5 months