Debian Codegraph @

modules/lvm2/udiskslinuxphysicalvolume.c

raw
1 /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
2 *
3 * Copyright (C) 2007-2010 David Zeuthen <[email protected]>
4 * Copyright (C) 2013 Marius Vollmer <[email protected]>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 *
20 */
21
22 #include "config.h"
23 #include <glib/gi18n-lib.h>
24
25 #include <blockdev/lvm.h>
26
27 #include <src/udiskslogging.h>
28 #include <src/udiskslinuxblockobject.h>
29 #include <src/udisksdaemon.h>
30 #include <src/udisksstate.h>
31 #include <src/udisksdaemonutil.h>
32 #include <src/udiskslinuxdevice.h>
33 #include <src/udiskslinuxprovider.h>
34
35 #include "udiskslinuxphysicalvolume.h"
36 #include "udiskslinuxvolumegroup.h"
37 #include "udiskslinuxvolumegroupobject.h"
38
39 /**
40 * SECTION:udiskslinuxphysicalvolume
41 * @title: UDisksLinuxPhysicalVolume
42 * @short_description: Linux implementation of #UDisksPhysicalVolume
43 *
44 * This type provides an implementation of the #UDisksPhysicalVolume
45 * interface on Linux.
46 */
47
48 typedef struct _UDisksLinuxPhysicalVolumeClass UDisksLinuxPhysicalVolumeClass;
49
50 /**
51 * UDisksLinuxPhysicalVolume:
52 *
53 * The #UDisksLinuxPhysicalVolume structure contains only private data and should
54 * only be accessed using the provided API.
55 */
56 struct _UDisksLinuxPhysicalVolume
57 {
58 UDisksPhysicalVolumeSkeleton parent_instance;
59 };
60
61 struct _UDisksLinuxPhysicalVolumeClass
62 {
63 UDisksPhysicalVolumeSkeletonClass parent_class;
64 };
65
66 static void physical_volume_iface_init (UDisksPhysicalVolumeIface *iface);
67
68 G_DEFINE_TYPE_WITH_CODE (UDisksLinuxPhysicalVolume, udisks_linux_physical_volume,
69 UDISKS_TYPE_PHYSICAL_VOLUME_SKELETON,
70 G_IMPLEMENT_INTERFACE (UDISKS_TYPE_PHYSICAL_VOLUME, physical_volume_iface_init));
71
72 /* ---------------------------------------------------------------------------------------------------- */
73
74 static void
75 udisks_linux_physical_volume_init (UDisksLinuxPhysicalVolume *physical_volume)
76 {
77 g_dbus_interface_skeleton_set_flags (G_DBUS_INTERFACE_SKELETON (physical_volume),
78 G_DBUS_INTERFACE_SKELETON_FLAGS_HANDLE_METHOD_INVOCATIONS_IN_THREAD);
79 }
80
81 static void
82 udisks_linux_physical_volume_constructed (GObject *_object)
83 {
84 if (G_OBJECT_CLASS (udisks_linux_physical_volume_parent_class)->constructed != NULL)
85 G_OBJECT_CLASS (udisks_linux_physical_volume_parent_class)->constructed (_object);
86 }
87
88 static void
89 udisks_linux_physical_volume_finalize (GObject *_object)
90 {
91 if (G_OBJECT_CLASS (udisks_linux_physical_volume_parent_class)->finalize != NULL)
92 G_OBJECT_CLASS (udisks_linux_physical_volume_parent_class)->finalize (_object);
93 }
94
95 static void
96 udisks_linux_physical_volume_class_init (UDisksLinuxPhysicalVolumeClass *klass)
97 {
98 GObjectClass *gobject_class;
99
100 gobject_class = G_OBJECT_CLASS (klass);
101 gobject_class->finalize = udisks_linux_physical_volume_finalize;
102 gobject_class->constructed = udisks_linux_physical_volume_constructed;
103 }
104
105 /**
106 * udisks_linux_physical_volume_new:
107 *
108 * Creates a new #UDisksLinuxPhysicalVolume instance.
109 *
110 * Returns: A new #UDisksLinuxPhysicalVolume. Free with g_object_unref().
111 */
112 UDisksPhysicalVolume *
113 udisks_linux_physical_volume_new (void)
114 {
115 return UDISKS_PHYSICAL_VOLUME (g_object_new (UDISKS_TYPE_LINUX_PHYSICAL_VOLUME,
116 NULL));
117 }
118
119 /* ---------------------------------------------------------------------------------------------------- */
120
121 /**
122 * udisks_linux_physical_volume_update:
123 * @physical_volume: A #UDisksLinuxPhysicalVolume.
124 * @object: The enclosing #UDisksLinuxBlockObject instance.
125 *
126 * Updates the interface.
127 */
128 void
129 udisks_linux_physical_volume_update (UDisksLinuxPhysicalVolume *physical_volume,
130 UDisksLinuxBlockObject *object,
131 UDisksLinuxVolumeGroupObject *group_object,
132 BDLVMPVdata *pv_info)
133 {
134 UDisksPhysicalVolume *iface;
135
136 iface = UDISKS_PHYSICAL_VOLUME (physical_volume);
137
138 udisks_physical_volume_set_volume_group (iface, g_dbus_object_get_object_path (G_DBUS_OBJECT (group_object)));
139
140 /* udiskslinuxvolumegroupobject.c:487 looks like we may not be given actual pv_info */
141 if (pv_info)
142 {
143 udisks_physical_volume_set_size (iface, pv_info->pv_size);
144 udisks_physical_volume_set_free_size (iface, pv_info->pv_free);
145 }
146
147 g_dbus_interface_skeleton_flush (G_DBUS_INTERFACE_SKELETON (iface));
148 }
149
150 /* ---------------------------------------------------------------------------------------------------- */
151
152 static void
153 physical_volume_iface_init (UDisksPhysicalVolumeIface *iface)
154 {
155 }
156
157 /* ---------------------------------------------------------------------------------------------------- */
158
159 void
160 udisks_linux_block_object_update_lvm_pv (UDisksLinuxBlockObject *object,
161 UDisksLinuxVolumeGroupObject *group_object,
162 BDLVMPVdata *pv_info)
163 {
164 UDisksPhysicalVolume *iface_physical_volume;
165
166 iface_physical_volume = udisks_object_peek_physical_volume (UDISKS_OBJECT (object));
167
168 if (group_object)
169 {
170 if (iface_physical_volume == NULL)
171 {
172 iface_physical_volume = udisks_linux_physical_volume_new ();
173 udisks_linux_physical_volume_update (UDISKS_LINUX_PHYSICAL_VOLUME (iface_physical_volume),
174 object, group_object, pv_info);
175 g_dbus_object_skeleton_add_interface (G_DBUS_OBJECT_SKELETON (object),
176 G_DBUS_INTERFACE_SKELETON (iface_physical_volume));
177 g_object_unref (iface_physical_volume);
178 }
179 else
180 udisks_linux_physical_volume_update (UDISKS_LINUX_PHYSICAL_VOLUME (iface_physical_volume),
181 object, group_object, pv_info);
182 }
183 else
184 {
185 if (iface_physical_volume != NULL)
186 g_dbus_object_skeleton_remove_interface (G_DBUS_OBJECT_SKELETON (object),
187 G_DBUS_INTERFACE_SKELETON (iface_physical_volume));
188 }
189 }