[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH] Install default storage pool

The attached patch adds a default pool definition to install
with libvirt. The pool is a directory pool, hardcoded to use
/var/lib/libvirt/images, though this is replaced with
%{_localstatedir}/lib/libvirt/images if installing via rpm.

Since /var/lib/libvirt/images may not exist if installing
from tar.gz, the pool is set not to autostart by default
via that method.

This patch isn't ready to apply though, since there is one
issue I don't know how to solve. We don't want every rpm
upgrade to install the default pool, since we don't want
the default to continually resurrect itself if a user
explicitly deletes it.

The default network handles this by checking if libvirtd
has been installed. Since libvirtd and virtual network
support were introduced around the same time, this makes
sense. However for storage, I can't think of any simple
check we can make. If we used the same as the default
network, all f8 or f9 upgrades wouldn't install the
default pool.

I can't really think of anything to check, besides maybe
doing some sort of time comparison on when 
/usr/share/libvirt/storage/default.xml was accessed. This
code is just hardcoded to always add it.

Any ideas?

diff --git a/libvirt.spec.in b/libvirt.spec.in
index 1b572ba..8b7c1b8 100644
--- a/libvirt.spec.in
+++ b/libvirt.spec.in
@@ -184,6 +184,19 @@ rm -f $RPM_BUILD_ROOT%{_sysconfdir}/libvirt/qemu/networks/default.xml
 rm -f $RPM_BUILD_ROOT%{_sysconfdir}/libvirt/qemu/networks/autostart/default.xml
 # Strip auto-generated UUID - we need it generated per-install
 sed -i -e "/<uuid>/d" $RPM_BUILD_ROOT%{_datadir}/libvirt/networks/default.xml
+install -d -m 0755 $RPM_BUILD_ROOT%{_datadir}/libvirt/storage/
+cp $RPM_BUILD_ROOT%{_sysconfdir}/libvirt/storage/default.xml \
+   $RPM_BUILD_ROOT%{_datadir}/libvirt/storage/default.xml
+rm -f $RPM_BUILD_ROOT%{_sysconfdir}/libvirt/storage/default.xml
+# Strip auto-generated UUID - we need it generated per-install
+sed -i -e "/<uuid>/d" $RPM_BUILD_ROOT%{_datadir}/libvirt/storage/default.xml
+# Strip default target path
+sed -i -e "/<path>/d" $RPM_BUILD_ROOT%{_datadir}/libvirt/storage/default.xml
+# Specify target path as generated 'images' dir
+sed -i -e "s,<target>,<target>\n    <path>%{_localstatedir}/lib/libvirt/images</path>," \
+          $RPM_BUILD_ROOT%{_datadir}/libvirt/storage/default.xml
 %find_lang %{name}
@@ -205,6 +218,17 @@ then
     ln -s ../default.xml %{_sysconfdir}/libvirt/qemu/networks/autostart/default.xml
+# We don't have the same luxury as the above, but I'm not sure what the
+# solution is. Unconditionally drop in the default storage pool for now...
+if /bin/true
+    UUID=`/usr/bin/uuidgen`
+    sed -e "s,</name>,</name>\n  <uuid>$UUID</uuid>," \
+         < %{_datadir}/libvirt/storage/default.xml \
+         > %{_sysconfdir}/libvirt/storage/default.xml
+    ln -s ../default.xml %{_sysconfdir}/libvirt/storage/autostart/default.xml
 /sbin/chkconfig --add libvirtd
@@ -227,6 +251,8 @@ fi
 %dir %attr(0700, root, root) %{_sysconfdir}/libvirt/qemu/
 %dir %attr(0700, root, root) %{_sysconfdir}/libvirt/qemu/networks/
 %dir %attr(0700, root, root) %{_sysconfdir}/libvirt/qemu/networks/autostart
+%dir %attr(0700, root, root) %{_sysconfdir}/libvirt/storage
+%dir %attr(0700, root, root) %{_sysconfdir}/libvirt/storage/autostart
 %config(noreplace) %{_sysconfdir}/sysconfig/libvirtd
 %config(noreplace) %{_sysconfdir}/libvirt/libvirtd.conf
@@ -234,7 +260,9 @@ fi
 %config(noreplace) %{_sysconfdir}/sasl2/libvirt.conf
 %dir %{_datadir}/libvirt/
 %dir %{_datadir}/libvirt/networks/
+%dir %{_datadir}/libvirt/storage/
 %dir %{_localstatedir}/run/libvirt/
 %dir %{_localstatedir}/lib/libvirt/
 %dir %attr(0700, root, root) %{_localstatedir}/lib/libvirt/images/
diff --git a/qemud/Makefile.am b/qemud/Makefile.am
index abf5e09..3c848b6 100644
--- a/qemud/Makefile.am
+++ b/qemud/Makefile.am
@@ -4,7 +4,8 @@ INCLUDES = $(LIBVIRT_FEATURES)
 # Distribute the generated files so that rpcgen isn't required on the
 # target machine (although almost any Unix machine will have it).
-EXTRA_DIST = libvirtd.init.in libvirtd.sysconf default-network.xml \
+EXTRA_DIST = libvirtd.init.in libvirtd.sysconf \
+    default-network.xml default-pool.xml\
 	remote_protocol.x \
 	remote_protocol.c remote_protocol.h \
 	remote_generate_stubs.pl rpcgen_fix.pl \
@@ -38,7 +39,8 @@ remote_protocol.c: remote_protocol.h
-UUID=$(shell uuidgen)
+NETUUID=$(shell uuidgen)
+POOLUUID=$(shell uuidgen)
 sbin_PROGRAMS = libvirtd
@@ -84,24 +86,33 @@ libvirtd_CFLAGS += $(AVAHI_CFLAGS)
 libvirtd_LDADD += $(AVAHI_LIBS)
-default_xml_dest = libvirt/qemu/networks/default.xml
+default_net_xml_dest = libvirt/qemu/networks/default.xml
+default_pool_xml_dest = libvirt/storage/default.xml
 install-data-local: install-init install-data-sasl install-data-polkit
 	mkdir -p $(DESTDIR)$(sysconfdir)/libvirt/qemu/networks/autostart
 	$(INSTALL_DATA) $(srcdir)/default-network.xml \
-	  $(DESTDIR)$(sysconfdir)/$(default_xml_dest)
-	sed -i -e "s,</name>,</name>\n  <uuid>$(UUID)</uuid>," \
-	  $(DESTDIR)$(sysconfdir)/$(default_xml_dest)
+	  $(DESTDIR)$(sysconfdir)/$(default_net_xml_dest)
+	sed -i -e "s,</name>,</name>\n  <uuid>$(NETUUID)</uuid>," \
+	  $(DESTDIR)$(sysconfdir)/$(default_net_xml_dest)
 	test -e $(DESTDIR)$(sysconfdir)/libvirt/qemu/networks/autostart/default.xml || \
            ln -s ../default.xml \
+	mkdir -p $(DESTDIR)$(sysconfdir)/libvirt/storage/autostart
+	$(INSTALL_DATA) $(srcdir)/default-pool.xml \
+	  $(DESTDIR)$(sysconfdir)/$(default_pool_xml_dest)
+	sed -i -e "s,</name>,</name>\n  <uuid>$(POOLUUID)</uuid>," \
+	  $(DESTDIR)$(sysconfdir)/$(default_pool_xml_dest)
 	mkdir -p $(DESTDIR)$(localstatedir)/log/libvirt/qemu
 	mkdir -p $(DESTDIR)$(localstatedir)/run/libvirt
 	mkdir -p $(DESTDIR)$(localstatedir)/lib/libvirt
 uninstall-local:: uninstall-init uninstall-data-sasl install-data-polkit
 	rm -f $(DESTDIR)$(sysconfdir)/libvirt/qemu/networks/autostart/default.xml
-	rm -f $(DESTDIR)$(sysconfdir)/$(default_xml_dest)
+	rm -f $(DESTDIR)$(sysconfdir)/$(default_net_xml_dest)
 	rmdir $(DESTDIR)$(sysconfdir)/libvirt/qemu/networks/autostart || :
+	rm -f $(DESTDIR)$(sysconfdir)/libvirt/storage/autostart/default.xml
+	rm -f $(DESTDIR)$(sysconfdir)/$(default_pool_xml_dest)
+	rmdir $(DESTDIR)$(sysconfdir)/libvirt/storage/autostart || :
 	rmdir $(DESTDIR)$(localstatedir)/log/libvirt/qemu || :
 	rmdir $(DESTDIR)$(localstatedir)/run/libvirt || :
 	rmdir $(DESTDIR)$(localstatedir)/lib/libvirt || :
diff --git a/qemud/default-pool.xml b/qemud/default-pool.xml
new file mode 100644
index 0000000..60fd88e
--- /dev/null
+++ b/qemud/default-pool.xml
@@ -0,0 +1,6 @@
+ <pool type='dir'>
+   <name>default</name>
+   <target>
+     <path>/var/lib/libvirt/images</path>
+   </target>
+ </pool>

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]