| 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 <fcntl.h> |
| 24 |
#include <glib/gi18n-lib.h> |
| 25 |
#include <stdio.h> |
| 26 |
|
| 27 |
#include <blockdev/lvm.h> |
| 28 |
|
| 29 |
#include <src/udiskslogging.h> |
| 30 |
#include <src/udiskslinuxblockobject.h> |
| 31 |
#include <src/udisksdaemon.h> |
| 32 |
#include <src/udisksstate.h> |
| 33 |
#include <src/udisksdaemonutil.h> |
| 34 |
#include <src/udiskslinuxdevice.h> |
| 35 |
#include <src/udiskslinuxblock.h> |
| 36 |
|
| 37 |
#include "udiskslinuxlogicalvolume.h" |
| 38 |
#include "udiskslinuxlogicalvolumeobject.h" |
| 39 |
#include "udiskslinuxvolumegroup.h" |
| 40 |
#include "udiskslinuxvolumegroupobject.h" |
| 41 |
|
| 42 |
#include "udiskslvm2daemonutil.h" |
| 43 |
#include "jobhelpers.h" |
| 44 |
|
| 45 |
/** |
| 46 |
* SECTION:udiskslinuxlogicalvolume |
| 47 |
* @title: UDisksLinuxLogicalVolume |
| 48 |
* @short_description: Linux implementation of #UDisksLogicalVolume |
| 49 |
* |
| 50 |
* This type provides an implementation of the #UDisksLogicalVolume |
| 51 |
* interface on Linux. |
| 52 |
*/ |
| 53 |
|
| 54 |
typedef struct _UDisksLinuxLogicalVolumeClass UDisksLinuxLogicalVolumeClass; |
| 55 |
|
| 56 |
/** |
| 57 |
* UDisksLinuxLogicalVolume: |
| 58 |
* |
| 59 |
* The #UDisksLinuxLogicalVolume structure contains only private data and should |
| 60 |
* only be accessed using the provided API. |
| 61 |
*/ |
| 62 |
struct _UDisksLinuxLogicalVolume |
| 63 |
{ |
| 64 |
UDisksLogicalVolumeSkeleton parent_instance; |
| 65 |
|
| 66 |
gboolean needs_udev_hack; |
| 67 |
}; |
| 68 |
|
| 69 |
struct _UDisksLinuxLogicalVolumeClass |
| 70 |
{ |
| 71 |
UDisksLogicalVolumeSkeletonClass parent_class; |
| 72 |
}; |
| 73 |
|
| 74 |
struct WaitData { |
| 75 |
UDisksLinuxVolumeGroupObject *group_object; |
| 76 |
const gchar *name; |
| 77 |
}; |
| 78 |
|
| 79 |
static void logical_volume_iface_init (UDisksLogicalVolumeIface *iface); |
| 80 |
static UDisksObject * wait_for_logical_volume_object (UDisksDaemon *daemon, gpointer user_data); |
| 81 |
|
| 82 |
G_DEFINE_TYPE_WITH_CODE (UDisksLinuxLogicalVolume, udisks_linux_logical_volume, |
| 83 |
UDISKS_TYPE_LOGICAL_VOLUME_SKELETON, |
| 84 |
G_IMPLEMENT_INTERFACE (UDISKS_TYPE_LOGICAL_VOLUME, logical_volume_iface_init)); |
| 85 |
|
| 86 |
/* ---------------------------------------------------------------------------------------------------- */ |
| 87 |
|
| 88 |
static void |
| 89 |
udisks_linux_logical_volume_init (UDisksLinuxLogicalVolume *logical_volume) |
| 90 |
{ |
| 91 |
logical_volume->needs_udev_hack = TRUE; |
| 92 |
g_dbus_interface_skeleton_set_flags (G_DBUS_INTERFACE_SKELETON (logical_volume), |
| 93 |
G_DBUS_INTERFACE_SKELETON_FLAGS_HANDLE_METHOD_INVOCATIONS_IN_THREAD); |
| 94 |
} |
| 95 |
|
| 96 |
static void |
| 97 |
udisks_linux_logical_volume_constructed (GObject *_object) |
| 98 |
{ |
| 99 |
if (G_OBJECT_CLASS (udisks_linux_logical_volume_parent_class)->constructed != NULL) |
| 100 |
G_OBJECT_CLASS (udisks_linux_logical_volume_parent_class)->constructed (_object); |
| 101 |
} |
| 102 |
|
| 103 |
static void |
| 104 |
udisks_linux_logical_volume_finalize (GObject *_object) |
| 105 |
{ |
| 106 |
if (G_OBJECT_CLASS (udisks_linux_logical_volume_parent_class)->finalize != NULL) |
| 107 |
G_OBJECT_CLASS (udisks_linux_logical_volume_parent_class)->finalize (_object); |
| 108 |
} |
| 109 |
|
| 110 |
static void |
| 111 |
udisks_linux_logical_volume_class_init (UDisksLinuxLogicalVolumeClass *klass) |
| 112 |
{ |
| 113 |
GObjectClass *gobject_class; |
| 114 |
|
| 115 |
gobject_class = G_OBJECT_CLASS (klass); |
| 116 |
gobject_class->finalize = udisks_linux_logical_volume_finalize; |
| 117 |
gobject_class->constructed = udisks_linux_logical_volume_constructed; |
| 118 |
} |
| 119 |
|
| 120 |
/** |
| 121 |
* udisks_linux_logical_volume_new: |
| 122 |
* |
| 123 |
* Creates a new #UDisksLinuxLogicalVolume instance. |
| 124 |
* |
| 125 |
* Returns: A new #UDisksLinuxLogicalVolume. Free with g_object_unref(). |
| 126 |
*/ |
| 127 |
UDisksLogicalVolume * |
| 128 |
udisks_linux_logical_volume_new (void) |
| 129 |
{ |
| 130 |
return UDISKS_LOGICAL_VOLUME (g_object_new (UDISKS_TYPE_LINUX_LOGICAL_VOLUME, |
| 131 |
NULL)); |
| 132 |
} |
| 133 |
|
| 134 |
/* ---------------------------------------------------------------------------------------------------- */ |
| 135 |
|
| 136 |
static GVariant * |
| 137 |
build_segment (UDisksDaemon *daemon, |
| 138 |
UDisksVolumeGroup *group, |
| 139 |
BDLVMSEGdata *seg) |
| 140 |
{ |
| 141 |
GVariantBuilder seg_builder; |
| 142 |
UDisksObject *block_object; |
| 143 |
guint64 extent_size = udisks_volume_group_get_extent_size (group); |
| 144 |
|
| 145 |
g_variant_builder_init (&seg_builder, G_VARIANT_TYPE ("(tto)")); |
| 146 |
g_variant_builder_add (&seg_builder, "t", seg->pv_start_pe * extent_size); |
| 147 |
g_variant_builder_add (&seg_builder, "t", seg->size_pe * extent_size); |
| 148 |
if (seg->pvdev == NULL) |
| 149 |
{ |
| 150 |
g_variant_builder_add (&seg_builder, "o", "/"); |
| 151 |
} |
| 152 |
else |
| 153 |
{ |
| 154 |
block_object = udisks_daemon_find_block_by_device_file_and_symlinks (daemon, seg->pvdev); |
| 155 |
if (block_object) |
| 156 |
{ |
| 157 |
g_variant_builder_add (&seg_builder, "o", g_dbus_object_get_object_path (G_DBUS_OBJECT (block_object))); |
| 158 |
g_object_unref (block_object); |
| 159 |
} |
| 160 |
else |
| 161 |
g_variant_builder_add (&seg_builder, "o", "/notfound"); |
| 162 |
} |
| 163 |
return g_variant_builder_end (&seg_builder); |
| 164 |
} |
| 165 |
|
| 166 |
static GVariant *build_structure (UDisksDaemon *daemon, UDisksVolumeGroup *group, BDLVMLVdata *lv, BDLVMLVdata **all); |
| 167 |
|
| 168 |
static gboolean |
| 169 |
lvnameeq (gchar *name, gchar *maybe_bracketed_name) |
| 170 |
{ |
| 171 |
size_t len = strlen (maybe_bracketed_name); |
| 172 |
return (g_strcmp0 (name, maybe_bracketed_name) == 0 |
| 173 |
|| (maybe_bracketed_name[0] == '[' |
| 174 |
&& maybe_bracketed_name[len-1] == ']' |
| 175 |
&& strlen (name) == len-2 |
| 176 |
&& strncmp (name, maybe_bracketed_name+1, len-2) == 0)); |
| 177 |
} |
| 178 |
|
| 179 |
static GVariant * |
| 180 |
build_structures (UDisksDaemon *daemon, |
| 181 |
UDisksVolumeGroup *group, |
| 182 |
gchar **lv_names, |
| 183 |
BDLVMLVdata **all) |
| 184 |
{ |
| 185 |
GVariantBuilder list_builder; |
| 186 |
g_variant_builder_init (&list_builder, G_VARIANT_TYPE ("aa{sv}")); |
| 187 |
for (int i = 0; lv_names[i]; i++) |
| 188 |
{ |
| 189 |
int j; |
| 190 |
for (j = 0; all[j]; j++) { |
| 191 |
if (lvnameeq (lv_names[i], all[j]->lv_name)) |
| 192 |
break; |
| 193 |
} |
| 194 |
if (all[j]) |
| 195 |
g_variant_builder_add_value (&list_builder, build_structure (daemon, group, all[j], all)); |
| 196 |
} |
| 197 |
return g_variant_builder_end (&list_builder); |
| 198 |
} |
| 199 |
|
| 200 |
static GVariant * |
| 201 |
build_structure (UDisksDaemon *daemon, |
| 202 |
UDisksVolumeGroup *group, |
| 203 |
BDLVMLVdata *lv, |
| 204 |
BDLVMLVdata **all) |
| 205 |
{ |
| 206 |
GVariantBuilder lv_builder; |
| 207 |
|
| 208 |
g_variant_builder_init (&lv_builder, G_VARIANT_TYPE_VARDICT); |
| 209 |
if (lv->lv_name[0] == '[') |
| 210 |
{ |
| 211 |
gchar *name = g_strndup (lv->lv_name + 1, strlen (lv->lv_name) - 2); |
| 212 |
g_variant_builder_add (&lv_builder, "{sv}", "name", g_variant_new_string (name)); |
| 213 |
g_free (name); |
| 214 |
} |
| 215 |
else |
| 216 |
g_variant_builder_add (&lv_builder, "{sv}", "name", g_variant_new_string (lv->lv_name)); |
| 217 |
|
| 218 |
g_variant_builder_add (&lv_builder, "{sv}", "type", g_variant_new_string (lv->segtype)); |
| 219 |
g_variant_builder_add (&lv_builder, "{sv}", "size", g_variant_new_uint64 (lv->size)); |
| 220 |
|
| 221 |
if (lv->segs) { |
| 222 |
GVariantBuilder segs_builder; |
| 223 |
g_variant_builder_init (&segs_builder, G_VARIANT_TYPE ("a(tto)")); |
| 224 |
for (int i = 0; lv->segs[i]; i++) |
| 225 |
g_variant_builder_add_value (&segs_builder, build_segment (daemon, group, lv->segs[i])); |
| 226 |
g_variant_builder_add (&lv_builder, "{sv}", "segments", g_variant_builder_end (&segs_builder)); |
| 227 |
} else { |
| 228 |
if (lv->data_lvs) |
| 229 |
g_variant_builder_add (&lv_builder, "{sv}", "data", build_structures (daemon, group, lv->data_lvs, all)); |
| 230 |
if (lv->metadata_lvs) |
| 231 |
g_variant_builder_add (&lv_builder, "{sv}", "metadata", build_structures (daemon, group, lv->metadata_lvs, all)); |
| 232 |
} |
| 233 |
|
| 234 |
return g_variant_builder_end (&lv_builder); |
| 235 |
} |
| 236 |
|
| 237 |
/** |
| 238 |
* udisks_linux_logical_volume_update: |
| 239 |
* @logical_volume: A #UDisksLinuxLogicalVolume. |
| 240 |
* @vg: LVM volume group |
| 241 |
* @lv: LVM logical volume |
| 242 |
* |
| 243 |
* Updates the interface. |
| 244 |
*/ |
| 245 |
void |
| 246 |
udisks_linux_logical_volume_update (UDisksLinuxLogicalVolume *logical_volume, |
| 247 |
UDisksLinuxVolumeGroupObject *group_object, |
| 248 |
BDLVMLVdata *lv_info, |
| 249 |
BDLVMLVdata *meta_lv_info, |
| 250 |
BDLVMLVdata **all_lv_infos, |
| 251 |
gboolean *needs_polling_ret) |
| 252 |
{ |
| 253 |
UDisksLinuxModuleLVM2 *module; |
| 254 |
UDisksDaemon *daemon; |
| 255 |
UDisksLogicalVolume *iface; |
| 256 |
UDisksVolumeGroup *group; |
| 257 |
const char *type; |
| 258 |
gboolean active; |
| 259 |
const char *pool_objpath; |
| 260 |
const char *origin_objpath; |
| 261 |
guint64 size = 0; |
| 262 |
|
| 263 |
module = udisks_linux_volume_group_object_get_module (group_object); |
| 264 |
daemon = udisks_module_get_daemon (UDISKS_MODULE (module)); |
| 265 |
|
| 266 |
iface = UDISKS_LOGICAL_VOLUME (logical_volume); |
| 267 |
group = udisks_object_get_volume_group (UDISKS_OBJECT (group_object)); |
| 268 |
|
| 269 |
udisks_logical_volume_set_name (iface, lv_info->lv_name); |
| 270 |
udisks_logical_volume_set_uuid (iface, lv_info->uuid); |
| 271 |
|
| 272 |
size = lv_info->size; |
| 273 |
type = "block"; |
| 274 |
active = FALSE; |
| 275 |
if (lv_info->attr) |
| 276 |
{ |
| 277 |
gchar volume_type = lv_info->attr[0]; |
| 278 |
gchar state = lv_info->attr[4]; |
| 279 |
gchar target_type = lv_info->attr[6]; |
| 280 |
|
| 281 |
if (target_type == 't') |
| 282 |
*needs_polling_ret = TRUE; |
| 283 |
|
| 284 |
if (target_type == 't' && volume_type == 't') |
| 285 |
type = "pool"; |
| 286 |
else if (volume_type == 'd') |
| 287 |
type = "vdopool"; |
| 288 |
if (meta_lv_info && meta_lv_info->size) |
| 289 |
size += meta_lv_info->size; |
| 290 |
|
| 291 |
if (state == 'a') |
| 292 |
active = TRUE; |
| 293 |
} |
| 294 |
udisks_logical_volume_set_type_ (iface, type); |
| 295 |
if (g_strcmp0 (lv_info->segtype, "error") == 0) |
| 296 |
udisks_logical_volume_set_layout (iface, "linear"); |
| 297 |
else |
| 298 |
udisks_logical_volume_set_layout (iface, lv_info->segtype); |
| 299 |
if ((g_str_has_prefix (lv_info->segtype, "raid") && g_strcmp0 (lv_info->segtype, "raid0") != 0) |
| 300 |
|| g_strcmp0 (lv_info->segtype, "mirror") == 0) |
| 301 |
{ |
| 302 |
udisks_logical_volume_set_sync_ratio (iface, lv_info->copy_percent / 100.0); |
| 303 |
if (lv_info->copy_percent != 100) |
| 304 |
*needs_polling_ret = TRUE; |
| 305 |
} |
| 306 |
else |
| 307 |
udisks_logical_volume_set_sync_ratio (iface, 1.0); |
| 308 |
|
| 309 |
udisks_logical_volume_set_active (iface, active); |
| 310 |
udisks_logical_volume_set_size (iface, size); |
| 311 |
|
| 312 |
/* LV is not active --> no block device |
| 313 |
XXX: Object path for active LVs is not set here because this runs before |
| 314 |
block device update, so it is possible that the block device is not |
| 315 |
added yet. BlockDevice property for active LVs is set when updating |
| 316 |
the block device. |
| 317 |
*/ |
| 318 |
if (!active) |
| 319 |
udisks_logical_volume_set_block_device (iface, "/"); |
| 320 |
|
| 321 |
udisks_logical_volume_set_data_allocated_ratio (iface, lv_info->data_percent / 100.0); |
| 322 |
udisks_logical_volume_set_metadata_allocated_ratio (iface, lv_info->metadata_percent / 100.0); |
| 323 |
|
| 324 |
pool_objpath = "/"; |
| 325 |
if (lv_info->pool_lv && g_strcmp0 (lv_info->segtype, "thin") == 0) |
| 326 |
{ |
| 327 |
UDisksLinuxLogicalVolumeObject *pool_object = udisks_linux_volume_group_object_find_logical_volume_object (group_object, lv_info->pool_lv); |
| 328 |
if (pool_object) |
| 329 |
pool_objpath = g_dbus_object_get_object_path (G_DBUS_OBJECT (pool_object)); |
| 330 |
} |
| 331 |
udisks_logical_volume_set_thin_pool (iface, pool_objpath); |
| 332 |
|
| 333 |
origin_objpath = "/"; |
| 334 |
if (lv_info->origin) |
| 335 |
{ |
| 336 |
UDisksLinuxLogicalVolumeObject *origin_object = udisks_linux_volume_group_object_find_logical_volume_object (group_object, lv_info->origin); |
| 337 |
if (origin_object) |
| 338 |
origin_objpath = g_dbus_object_get_object_path (G_DBUS_OBJECT (origin_object)); |
| 339 |
} |
| 340 |
udisks_logical_volume_set_origin (iface, origin_objpath); |
| 341 |
|
| 342 |
udisks_logical_volume_set_volume_group (iface, g_dbus_object_get_object_path (G_DBUS_OBJECT (group_object))); |
| 343 |
|
| 344 |
if (logical_volume->needs_udev_hack) |
| 345 |
{ |
| 346 |
gchar *dev_file = g_strdup_printf ("/dev/%s/%s", lv_info->vg_name, lv_info->lv_name); |
| 347 |
/* LVM2 versions before 2.02.105 sometimes incorrectly leave the |
| 348 |
* DM_UDEV_DISABLE_OTHER_RULES flag set for thin volumes. As a |
| 349 |
* workaround, we trigger an extra udev "change" event which |
| 350 |
* will clear this up. |
| 351 |
* |
| 352 |
* https://www.redhat.com/archives/linux-lvm/2014-January/msg00030.html |
| 353 |
*/ |
| 354 |
udisks_daemon_util_lvm2_trigger_udev (dev_file); |
| 355 |
logical_volume->needs_udev_hack = FALSE; |
| 356 |
g_free (dev_file); |
| 357 |
} |
| 358 |
|
| 359 |
udisks_logical_volume_set_structure (iface, build_structure (daemon, group, lv_info, all_lv_infos)); |
| 360 |
|
| 361 |
g_dbus_interface_skeleton_flush (G_DBUS_INTERFACE_SKELETON (iface)); |
| 362 |
g_clear_object (&group); |
| 363 |
} |
| 364 |
|
| 365 |
void |
| 366 |
udisks_linux_logical_volume_update_etctabs (UDisksLinuxLogicalVolume *logical_volume, |
| 367 |
UDisksLinuxVolumeGroupObject *group_object) |
| 368 |
{ |
| 369 |
UDisksLinuxModuleLVM2 *module; |
| 370 |
UDisksDaemon *daemon; |
| 371 |
UDisksLogicalVolume *iface; |
| 372 |
const gchar *uuid; |
| 373 |
|
| 374 |
module = udisks_linux_volume_group_object_get_module (group_object); |
| 375 |
daemon = udisks_module_get_daemon (UDISKS_MODULE (module)); |
| 376 |
iface = UDISKS_LOGICAL_VOLUME (logical_volume); |
| 377 |
uuid = udisks_logical_volume_get_uuid (iface); |
| 378 |
|
| 379 |
udisks_logical_volume_set_child_configuration (iface, |
| 380 |
udisks_linux_find_child_configuration (daemon, |
| 381 |
uuid)); |
| 382 |
g_dbus_interface_skeleton_flush (G_DBUS_INTERFACE_SKELETON (iface)); |
| 383 |
} |
| 384 |
|
| 385 |
/* ---------------------------------------------------------------------------------------------------- */ |
| 386 |
|
| 387 |
static UDisksBlock * |
| 388 |
peek_block_for_logical_volume (UDisksLogicalVolume *volume, |
| 389 |
UDisksDaemon *daemon) |
| 390 |
{ |
| 391 |
UDisksBlock *ret = NULL; |
| 392 |
GDBusObject *object; |
| 393 |
GList *l, *objects = NULL; |
| 394 |
UDisksBlockLVM2 *block_lvm2; |
| 395 |
|
| 396 |
object = g_dbus_interface_get_object (G_DBUS_INTERFACE (volume)); |
| 397 |
if (object == NULL) |
| 398 |
goto out; |
| 399 |
|
| 400 |
objects = udisks_daemon_get_objects (daemon); |
| 401 |
for (l = objects; l != NULL; l = l->next) |
| 402 |
{ |
| 403 |
block_lvm2 = udisks_object_peek_block_lvm2 (UDISKS_OBJECT(l->data)); |
| 404 |
if (block_lvm2 && |
| 405 |
g_strcmp0 (udisks_block_lvm2_get_logical_volume (block_lvm2), |
| 406 |
g_dbus_object_get_object_path (object)) == 0) |
| 407 |
{ |
| 408 |
ret = udisks_object_peek_block (UDISKS_OBJECT(l->data)); |
| 409 |
goto out; |
| 410 |
} |
| 411 |
} |
| 412 |
|
| 413 |
out: |
| 414 |
g_list_free_full (objects, g_object_unref); |
| 415 |
return ret; |
| 416 |
} |
| 417 |
|
| 418 |
gboolean |
| 419 |
udisks_linux_logical_volume_teardown_block (UDisksLogicalVolume *volume, |
| 420 |
UDisksDaemon *daemon, |
| 421 |
GDBusMethodInvocation *invocation, |
| 422 |
GVariant *options, |
| 423 |
GError **error) |
| 424 |
{ |
| 425 |
UDisksBlock *block; |
| 426 |
|
| 427 |
block = peek_block_for_logical_volume (volume, daemon); |
| 428 |
if (block) |
| 429 |
{ |
| 430 |
/* The volume is active. Tear down its block device. |
| 431 |
*/ |
| 432 |
if (!udisks_linux_block_teardown (block, |
| 433 |
invocation, |
| 434 |
options, |
| 435 |
error)) |
| 436 |
return FALSE; |
| 437 |
} |
| 438 |
else |
| 439 |
{ |
| 440 |
/* The volume is inactive. Remove the child configurations. |
| 441 |
*/ |
| 442 |
if (!udisks_linux_remove_configuration (udisks_logical_volume_get_child_configuration (volume), |
| 443 |
error)) |
| 444 |
return FALSE; |
| 445 |
} |
| 446 |
|
| 447 |
return TRUE; |
| 448 |
} |
| 449 |
|
| 450 |
static gboolean |
| 451 |
teardown_logical_volume (UDisksLogicalVolume *volume, |
| 452 |
UDisksDaemon *daemon, |
| 453 |
GDBusMethodInvocation *invocation, |
| 454 |
GVariant *options, |
| 455 |
GError **error) |
| 456 |
{ |
| 457 |
GDBusObject *volume_object; |
| 458 |
UDisksObject *group_object; |
| 459 |
UDisksVolumeGroup *group; |
| 460 |
UDisksLogicalVolume *sibling_volume; |
| 461 |
GList *siblings; |
| 462 |
GList *l; |
| 463 |
|
| 464 |
if (!udisks_linux_logical_volume_teardown_block (volume, |
| 465 |
daemon, |
| 466 |
invocation, |
| 467 |
options, |
| 468 |
error)) |
| 469 |
return FALSE; |
| 470 |
|
| 471 |
/* Recurse for pool members and snapshots. |
| 472 |
*/ |
| 473 |
|
| 474 |
volume_object = g_dbus_interface_get_object (G_DBUS_INTERFACE (volume)); |
| 475 |
group_object = udisks_daemon_find_object (daemon, udisks_logical_volume_get_volume_group (volume)); |
| 476 |
if (volume_object && group_object) |
| 477 |
{ |
| 478 |
group = udisks_object_peek_volume_group (group_object); |
| 479 |
if (group) |
| 480 |
{ |
| 481 |
siblings = udisks_linux_volume_group_get_logical_volumes (group, daemon); |
| 482 |
for (l = siblings; l; l = l->next) |
| 483 |
{ |
| 484 |
sibling_volume = UDISKS_LOGICAL_VOLUME (l->data); |
| 485 |
if (g_strcmp0 (udisks_logical_volume_get_thin_pool (sibling_volume), |
| 486 |
g_dbus_object_get_object_path (volume_object)) == 0 || |
| 487 |
g_strcmp0 (udisks_logical_volume_get_origin (sibling_volume), |
| 488 |
g_dbus_object_get_object_path (volume_object)) == 0) |
| 489 |
{ |
| 490 |
if (!teardown_logical_volume (sibling_volume, |
| 491 |
daemon, |
| 492 |
invocation, |
| 493 |
options, |
| 494 |
error)) |
| 495 |
{ |
| 496 |
g_list_free_full (siblings, g_object_unref); |
| 497 |
g_clear_object (&group_object); |
| 498 |
return FALSE; |
| 499 |
} |
| 500 |
} |
| 501 |
} |
| 502 |
g_list_free_full (siblings, g_object_unref); |
| 503 |
} |
| 504 |
} |
| 505 |
|
| 506 |
g_clear_object (&group_object); |
| 507 |
return TRUE; |
| 508 |
} |
| 509 |
|
| 510 |
static gboolean |
| 511 |
common_setup (UDisksLinuxLogicalVolume *volume, |
| 512 |
GDBusMethodInvocation *invocation, |
| 513 |
GVariant *options, |
| 514 |
const gchar *auth_err_msg, |
| 515 |
UDisksLinuxLogicalVolumeObject **object, |
| 516 |
UDisksDaemon **daemon, |
| 517 |
uid_t *out_uid) |
| 518 |
{ |
| 519 |
UDisksLinuxModuleLVM2 *module; |
| 520 |
gboolean rc = FALSE; |
| 521 |
GError *error = NULL; |
| 522 |
|
| 523 |
*object = udisks_daemon_util_dup_object (volume, &error); |
| 524 |
if (*object == NULL) |
| 525 |
{ |
| 526 |
g_dbus_method_invocation_take_error (invocation, error); |
| 527 |
goto out; |
| 528 |
} |
| 529 |
|
| 530 |
module = udisks_linux_logical_volume_object_get_module (*object); |
| 531 |
*daemon = udisks_module_get_daemon (UDISKS_MODULE (module)); |
| 532 |
|
| 533 |
if (!udisks_daemon_util_get_caller_uid_sync (*daemon, |
| 534 |
invocation, |
| 535 |
NULL /* GCancellable */, |
| 536 |
out_uid, |
| 537 |
&error)) |
| 538 |
{ |
| 539 |
g_dbus_method_invocation_take_error (invocation, error); |
| 540 |
goto out; |
| 541 |
} |
| 542 |
|
| 543 |
/* Policy check. */ |
| 544 |
UDISKS_DAEMON_CHECK_AUTHORIZATION (*daemon, |
| 545 |
UDISKS_OBJECT (*object), |
| 546 |
LVM2_POLICY_ACTION_ID, |
| 547 |
options, |
| 548 |
auth_err_msg, |
| 549 |
invocation); |
| 550 |
rc = TRUE; |
| 551 |
out: |
| 552 |
return rc; |
| 553 |
} |
| 554 |
|
| 555 |
static gboolean |
| 556 |
handle_delete (UDisksLogicalVolume *_volume, |
| 557 |
GDBusMethodInvocation *invocation, |
| 558 |
GVariant *options) |
| 559 |
{ |
| 560 |
GError *error = NULL; |
| 561 |
UDisksLinuxLogicalVolume *volume = UDISKS_LINUX_LOGICAL_VOLUME (_volume); |
| 562 |
UDisksLinuxLogicalVolumeObject *object = NULL; |
| 563 |
UDisksDaemon *daemon = NULL; |
| 564 |
uid_t caller_uid; |
| 565 |
gboolean teardown_flag = FALSE; |
| 566 |
UDisksLinuxVolumeGroupObject *group_object; |
| 567 |
LVJobData data = {0,}; |
| 568 |
struct WaitData wait_data; |
| 569 |
|
| 570 |
g_variant_lookup (options, "tear-down", "b", &teardown_flag); |
| 571 |
|
| 572 |
if (!common_setup (volume, invocation, options, |
| 573 |
N_("Authentication is required to delete a logical volume"), |
| 574 |
&object, &daemon, &caller_uid)) |
| 575 |
goto out; |
| 576 |
|
| 577 |
if (teardown_flag && |
| 578 |
!teardown_logical_volume (_volume, |
| 579 |
daemon, |
| 580 |
invocation, |
| 581 |
options, |
| 582 |
&error)) |
| 583 |
{ |
| 584 |
g_dbus_method_invocation_take_error (invocation, error); |
| 585 |
goto out; |
| 586 |
} |
| 587 |
|
| 588 |
group_object = udisks_linux_logical_volume_object_get_volume_group (object); |
| 589 |
data.vg_name = udisks_linux_volume_group_object_get_name (group_object); |
| 590 |
data.lv_name = udisks_linux_logical_volume_object_get_name (object); |
| 591 |
|
| 592 |
if (!udisks_daemon_launch_threaded_job_sync (daemon, |
| 593 |
UDISKS_OBJECT (object), |
| 594 |
"lvm-lvol-delete", |
| 595 |
caller_uid, |
| 596 |
FALSE, |
| 597 |
lvremove_job_func, |
| 598 |
&data, |
| 599 |
NULL, /* user_data_free_func */ |
| 600 |
NULL, /* GCancellable */ |
| 601 |
&error)) |
| 602 |
{ |
| 603 |
g_dbus_method_invocation_return_error (invocation, |
| 604 |
UDISKS_ERROR, |
| 605 |
UDISKS_ERROR_FAILED, |
| 606 |
"Error deleting logical volume: %s", |
| 607 |
error->message); |
| 608 |
g_clear_error (&error); |
| 609 |
goto out; |
| 610 |
} |
| 611 |
|
| 612 |
wait_data.group_object = group_object; |
| 613 |
wait_data.name = data.lv_name; |
| 614 |
|
| 615 |
if (! udisks_daemon_wait_for_object_to_disappear_sync (daemon, |
| 616 |
wait_for_logical_volume_object, |
| 617 |
&wait_data, |
| 618 |
NULL, |
| 619 |
UDISKS_DEFAULT_WAIT_TIMEOUT, |
| 620 |
&error)) |
| 621 |
{ |
| 622 |
g_prefix_error (&error, |
| 623 |
"Error waiting for block object to disappear after deleting '%s': ", |
| 624 |
udisks_logical_volume_get_name (_volume)); |
| 625 |
g_dbus_method_invocation_take_error (invocation, error); |
| 626 |
goto out; |
| 627 |
} |
| 628 |
|
| 629 |
udisks_logical_volume_complete_delete (_volume, invocation); |
| 630 |
|
| 631 |
out: |
| 632 |
g_clear_object (&object); |
| 633 |
return TRUE; |
| 634 |
} |
| 635 |
|
| 636 |
/* ---------------------------------------------------------------------------------------------------- */ |
| 637 |
|
| 638 |
static gboolean |
| 639 |
handle_repair (UDisksLogicalVolume *_volume, |
| 640 |
GDBusMethodInvocation *invocation, |
| 641 |
const gchar *const *arg_pvs, |
| 642 |
GVariant *options) |
| 643 |
{ |
| 644 |
GError *error = NULL; |
| 645 |
UDisksLinuxLogicalVolume *volume = UDISKS_LINUX_LOGICAL_VOLUME (_volume); |
| 646 |
UDisksLinuxLogicalVolumeObject *object = NULL; |
| 647 |
UDisksDaemon *daemon = NULL; |
| 648 |
uid_t caller_uid; |
| 649 |
UDisksLinuxVolumeGroupObject *group_object; |
| 650 |
LVJobData data = {0,}; |
| 651 |
g_auto(GStrv) pvs = NULL; |
| 652 |
|
| 653 |
if (!common_setup (volume, invocation, options, |
| 654 |
N_("Authentication is required to repair a logical volume"), |
| 655 |
&object, &daemon, &caller_uid)) |
| 656 |
goto out; |
| 657 |
|
| 658 |
group_object = udisks_linux_logical_volume_object_get_volume_group (object); |
| 659 |
data.vg_name = udisks_linux_volume_group_object_get_name (group_object); |
| 660 |
data.lv_name = udisks_linux_logical_volume_object_get_name (object); |
| 661 |
pvs = udisks_daemon_util_lvm2_gather_pvs (daemon, group_object, arg_pvs, &error); |
| 662 |
if (pvs == NULL) |
| 663 |
{ |
| 664 |
g_dbus_method_invocation_take_error (invocation, error); |
| 665 |
goto out; |
| 666 |
} |
| 667 |
data.new_lv_pvs = (const gchar **)pvs; |
| 668 |
|
| 669 |
if (!udisks_daemon_launch_threaded_job_sync (daemon, |
| 670 |
UDISKS_OBJECT (object), |
| 671 |
"lvm-lvol-repair", |
| 672 |
caller_uid, |
| 673 |
FALSE, |
| 674 |
lvrepair_job_func, |
| 675 |
&data, |
| 676 |
NULL, /* user_data_free_func */ |
| 677 |
NULL, /* GCancellable */ |
| 678 |
&error)) |
| 679 |
{ |
| 680 |
g_dbus_method_invocation_return_error (invocation, |
| 681 |
UDISKS_ERROR, |
| 682 |
UDISKS_ERROR_FAILED, |
| 683 |
"Error repairing logical volume: %s", |
| 684 |
error->message); |
| 685 |
g_clear_error (&error); |
| 686 |
goto out; |
| 687 |
} |
| 688 |
|
| 689 |
udisks_logical_volume_complete_repair (_volume, invocation); |
| 690 |
|
| 691 |
out: |
| 692 |
g_clear_object (&object); |
| 693 |
return TRUE; |
| 694 |
} |
| 695 |
|
| 696 |
/* ---------------------------------------------------------------------------------------------------- */ |
| 697 |
|
| 698 |
static UDisksObject * |
| 699 |
wait_for_logical_volume_object (UDisksDaemon *daemon, |
| 700 |
gpointer user_data) |
| 701 |
{ |
| 702 |
struct WaitData *data = user_data; |
| 703 |
UDisksLinuxLogicalVolumeObject *object; |
| 704 |
|
| 705 |
object = udisks_linux_volume_group_object_find_logical_volume_object (data->group_object, data->name); |
| 706 |
if (object == NULL) |
| 707 |
return NULL; |
| 708 |
|
| 709 |
return g_object_ref (UDISKS_OBJECT (object)); |
| 710 |
} |
| 711 |
|
| 712 |
static const gchar * |
| 713 |
wait_for_logical_volume_path (UDisksLinuxVolumeGroupObject *group_object, |
| 714 |
const gchar *name, |
| 715 |
GError **error) |
| 716 |
{ |
| 717 |
struct WaitData data; |
| 718 |
UDisksLinuxModuleLVM2 *module; |
| 719 |
UDisksDaemon *daemon; |
| 720 |
UDisksObject *volume_object; |
| 721 |
const gchar *object_path; |
| 722 |
|
| 723 |
data.group_object = group_object; |
| 724 |
data.name = name; |
| 725 |
module = udisks_linux_volume_group_object_get_module (group_object); |
| 726 |
daemon = udisks_module_get_daemon (UDISKS_MODULE (module)); |
| 727 |
volume_object = udisks_daemon_wait_for_object_sync (daemon, |
| 728 |
wait_for_logical_volume_object, |
| 729 |
&data, |
| 730 |
NULL, |
| 731 |
UDISKS_DEFAULT_WAIT_TIMEOUT, |
| 732 |
error); |
| 733 |
if (volume_object == NULL) |
| 734 |
return NULL; |
| 735 |
|
| 736 |
object_path = g_dbus_object_get_object_path (G_DBUS_OBJECT (volume_object)); |
| 737 |
g_object_unref (volume_object); |
| 738 |
|
| 739 |
return object_path; |
| 740 |
} |
| 741 |
|
| 742 |
static gboolean |
| 743 |
handle_rename (UDisksLogicalVolume *_volume, |
| 744 |
GDBusMethodInvocation *invocation, |
| 745 |
const gchar *new_name, |
| 746 |
GVariant *options) |
| 747 |
{ |
| 748 |
GError *error = NULL; |
| 749 |
UDisksLinuxLogicalVolume *volume = UDISKS_LINUX_LOGICAL_VOLUME (_volume); |
| 750 |
UDisksLinuxLogicalVolumeObject *object = NULL; |
| 751 |
UDisksDaemon *daemon; |
| 752 |
uid_t caller_uid; |
| 753 |
UDisksLinuxVolumeGroupObject *group_object; |
| 754 |
const gchar *lv_objpath; |
| 755 |
LVJobData data = {0,}; |
| 756 |
|
| 757 |
if (!common_setup (volume, invocation, options, |
| 758 |
N_("Authentication is required to rename a logical volume"), |
| 759 |
&object, &daemon, &caller_uid)) |
| 760 |
goto out; |
| 761 |
|
| 762 |
group_object = udisks_linux_logical_volume_object_get_volume_group (object); |
| 763 |
data.vg_name = udisks_linux_volume_group_object_get_name (group_object); |
| 764 |
data.lv_name = udisks_linux_logical_volume_object_get_name (object); |
| 765 |
data.new_lv_name = new_name; |
| 766 |
|
| 767 |
if (!udisks_daemon_launch_threaded_job_sync (daemon, |
| 768 |
UDISKS_OBJECT (object), |
| 769 |
"lvm-lvol-rename", |
| 770 |
caller_uid, |
| 771 |
FALSE, |
| 772 |
lvrename_job_func, |
| 773 |
&data, |
| 774 |
NULL, /* user_data_free_func */ |
| 775 |
NULL, /* GCancellable */ |
| 776 |
&error)) |
| 777 |
{ |
| 778 |
g_dbus_method_invocation_return_error (invocation, |
| 779 |
UDISKS_ERROR, |
| 780 |
UDISKS_ERROR_FAILED, |
| 781 |
"Error renaming logical volume: %s", |
| 782 |
error->message); |
| 783 |
g_clear_error (&error); |
| 784 |
goto out; |
| 785 |
} |
| 786 |
|
| 787 |
lv_objpath = wait_for_logical_volume_path (group_object, new_name, &error); |
| 788 |
if (lv_objpath == NULL) |
| 789 |
{ |
| 790 |
g_prefix_error (&error, |
| 791 |
"Error waiting for logical volume object for '%s': ", |
| 792 |
new_name); |
| 793 |
g_dbus_method_invocation_take_error (invocation, error); |
| 794 |
goto out; |
| 795 |
} |
| 796 |
|
| 797 |
udisks_logical_volume_complete_rename (_volume, invocation, lv_objpath); |
| 798 |
|
| 799 |
out: |
| 800 |
g_clear_object (&object); |
| 801 |
return TRUE; |
| 802 |
} |
| 803 |
|
| 804 |
/* ---------------------------------------------------------------------------------------------------- */ |
| 805 |
|
| 806 |
static gboolean |
| 807 |
handle_resize (UDisksLogicalVolume *_volume, |
| 808 |
GDBusMethodInvocation *invocation, |
| 809 |
guint64 new_size, |
| 810 |
GVariant *options) |
| 811 |
{ |
| 812 |
GError *error = NULL; |
| 813 |
UDisksLinuxLogicalVolume *volume = UDISKS_LINUX_LOGICAL_VOLUME (_volume); |
| 814 |
UDisksLinuxLogicalVolumeObject *object = NULL; |
| 815 |
UDisksDaemon *daemon; |
| 816 |
uid_t caller_uid; |
| 817 |
UDisksLinuxVolumeGroupObject *group_object; |
| 818 |
LVJobData data = {0,}; |
| 819 |
gchar **opt_pvs = NULL; |
| 820 |
g_auto(GStrv) pvs = NULL; |
| 821 |
|
| 822 |
if (!common_setup (volume, invocation, options, |
| 823 |
N_("Authentication is required to resize a logical volume"), |
| 824 |
&object, &daemon, &caller_uid)) |
| 825 |
goto out; |
| 826 |
|
| 827 |
group_object = udisks_linux_logical_volume_object_get_volume_group (object); |
| 828 |
data.vg_name = udisks_linux_volume_group_object_get_name (group_object); |
| 829 |
data.lv_name = udisks_linux_logical_volume_object_get_name (object); |
| 830 |
data.new_lv_size = new_size; |
| 831 |
|
| 832 |
data.resize_fs = FALSE; |
| 833 |
data.force = FALSE; |
| 834 |
g_variant_lookup (options, "resize_fsys", "b", &(data.resize_fs)); |
| 835 |
g_variant_lookup (options, "force", "b", &(data.force)); |
| 836 |
g_variant_lookup (options, "pvs", "^a&o", &opt_pvs); |
| 837 |
|
| 838 |
if (opt_pvs) |
| 839 |
{ |
| 840 |
pvs = udisks_daemon_util_lvm2_gather_pvs (daemon, group_object, (const gchar **)opt_pvs, &error); |
| 841 |
if (pvs == NULL) |
| 842 |
{ |
| 843 |
g_dbus_method_invocation_take_error (invocation, error); |
| 844 |
goto out; |
| 845 |
} |
| 846 |
} |
| 847 |
|
| 848 |
data.new_lv_pvs = (const gchar **)pvs; |
| 849 |
|
| 850 |
if (!udisks_daemon_launch_threaded_job_sync (daemon, |
| 851 |
UDISKS_OBJECT (object), |
| 852 |
"lvm-lvol-resize", |
| 853 |
caller_uid, |
| 854 |
FALSE, |
| 855 |
lvresize_job_func, |
| 856 |
&data, |
| 857 |
NULL, /* user_data_free_func */ |
| 858 |
NULL, /* GCancellable */ |
| 859 |
&error)) |
| 860 |
{ |
| 861 |
g_dbus_method_invocation_return_error (invocation, |
| 862 |
UDISKS_ERROR, |
| 863 |
UDISKS_ERROR_FAILED, |
| 864 |
"Error resizing logical volume: %s", |
| 865 |
error->message); |
| 866 |
g_clear_error (&error); |
| 867 |
goto out; |
| 868 |
} |
| 869 |
|
| 870 |
udisks_logical_volume_complete_resize (_volume, invocation); |
| 871 |
|
| 872 |
out: |
| 873 |
g_clear_object (&object); |
| 874 |
g_free (opt_pvs); |
| 875 |
return TRUE; |
| 876 |
} |
| 877 |
|
| 878 |
/* ---------------------------------------------------------------------------------------------------- */ |
| 879 |
|
| 880 |
struct WaitForBlockData { |
| 881 |
UDisksLinuxLogicalVolumeObject *volume_object; |
| 882 |
}; |
| 883 |
|
| 884 |
static UDisksObject * |
| 885 |
wait_for_logical_volume_block_object (UDisksDaemon *daemon, |
| 886 |
gpointer user_data) |
| 887 |
{ |
| 888 |
UDisksLinuxLogicalVolumeObject *volume_object = user_data; |
| 889 |
const gchar *volume_objpath; |
| 890 |
GList *objects, *l; |
| 891 |
UDisksObject *ret = NULL; |
| 892 |
|
| 893 |
volume_objpath = g_dbus_object_get_object_path (G_DBUS_OBJECT (volume_object)); |
| 894 |
|
| 895 |
objects = udisks_daemon_get_objects (daemon); |
| 896 |
for (l = objects; l != NULL; l = l->next) |
| 897 |
{ |
| 898 |
UDisksObject *object = UDISKS_OBJECT (l->data); |
| 899 |
UDisksBlockLVM2 *block; |
| 900 |
|
| 901 |
block = udisks_object_peek_block_lvm2 (object); |
| 902 |
if (block == NULL) |
| 903 |
continue; |
| 904 |
|
| 905 |
if (g_strcmp0 (udisks_block_lvm2_get_logical_volume (block), volume_objpath) == 0) |
| 906 |
{ |
| 907 |
ret = g_object_ref (object); |
| 908 |
goto out; |
| 909 |
} |
| 910 |
} |
| 911 |
|
| 912 |
out: |
| 913 |
g_list_free_full (objects, g_object_unref); |
| 914 |
return ret; |
| 915 |
} |
| 916 |
|
| 917 |
static gboolean |
| 918 |
handle_activate (UDisksLogicalVolume *_volume, |
| 919 |
GDBusMethodInvocation *invocation, |
| 920 |
GVariant *options) |
| 921 |
{ |
| 922 |
GError *error = NULL; |
| 923 |
UDisksLinuxLogicalVolume *volume = UDISKS_LINUX_LOGICAL_VOLUME (_volume); |
| 924 |
UDisksLinuxLogicalVolumeObject *object = NULL; |
| 925 |
UDisksDaemon *daemon; |
| 926 |
uid_t caller_uid; |
| 927 |
UDisksLinuxVolumeGroupObject *group_object; |
| 928 |
UDisksObject *block_object = NULL; |
| 929 |
LVJobData data = {0,}; |
| 930 |
|
| 931 |
if (!common_setup (volume, invocation, options, |
| 932 |
N_("Authentication is required to activate a logical volume"), |
| 933 |
&object, &daemon, &caller_uid)) |
| 934 |
goto out; |
| 935 |
|
| 936 |
group_object = udisks_linux_logical_volume_object_get_volume_group (object); |
| 937 |
data.vg_name = udisks_linux_volume_group_object_get_name (group_object); |
| 938 |
data.lv_name = udisks_linux_logical_volume_object_get_name (object); |
| 939 |
|
| 940 |
if (!udisks_daemon_launch_threaded_job_sync (daemon, |
| 941 |
UDISKS_OBJECT (object), |
| 942 |
"lvm-lvol-activate", |
| 943 |
caller_uid, |
| 944 |
FALSE, |
| 945 |
lvactivate_job_func, |
| 946 |
&data, |
| 947 |
NULL, /* user_data_free_func */ |
| 948 |
NULL, /* GCancellable */ |
| 949 |
&error)) |
| 950 |
|
| 951 |
{ |
| 952 |
g_dbus_method_invocation_return_error (invocation, |
| 953 |
UDISKS_ERROR, |
| 954 |
UDISKS_ERROR_FAILED, |
| 955 |
"Error activating logical volume: %s", |
| 956 |
error->message); |
| 957 |
g_clear_error (&error); |
| 958 |
goto out; |
| 959 |
} |
| 960 |
|
| 961 |
block_object = udisks_daemon_wait_for_object_sync (daemon, |
| 962 |
wait_for_logical_volume_block_object, |
| 963 |
object, |
| 964 |
NULL, |
| 965 |
UDISKS_DEFAULT_WAIT_TIMEOUT, |
| 966 |
&error); |
| 967 |
if (block_object == NULL) |
| 968 |
{ |
| 969 |
g_prefix_error (&error, |
| 970 |
"Error waiting for block object for '%s': ", |
| 971 |
udisks_logical_volume_get_name (_volume)); |
| 972 |
g_dbus_method_invocation_take_error (invocation, error); |
| 973 |
goto out; |
| 974 |
} |
| 975 |
|
| 976 |
udisks_logical_volume_complete_activate (_volume, invocation, |
| 977 |
g_dbus_object_get_object_path (G_DBUS_OBJECT (block_object))); |
| 978 |
|
| 979 |
out: |
| 980 |
g_clear_object (&block_object); |
| 981 |
g_clear_object (&object); |
| 982 |
return TRUE; |
| 983 |
} |
| 984 |
|
| 985 |
/* ---------------------------------------------------------------------------------------------------- */ |
| 986 |
|
| 987 |
static gboolean |
| 988 |
handle_deactivate (UDisksLogicalVolume *_volume, |
| 989 |
GDBusMethodInvocation *invocation, |
| 990 |
GVariant *options) |
| 991 |
{ |
| 992 |
GError *error = NULL; |
| 993 |
UDisksLinuxLogicalVolume *volume = UDISKS_LINUX_LOGICAL_VOLUME (_volume); |
| 994 |
UDisksLinuxLogicalVolumeObject *object = NULL; |
| 995 |
UDisksDaemon *daemon; |
| 996 |
uid_t caller_uid; |
| 997 |
UDisksLinuxVolumeGroupObject *group_object; |
| 998 |
LVJobData data = {0,}; |
| 999 |
|
| 1000 |
if (!common_setup (volume, invocation, options, |
| 1001 |
N_("Authentication is required to deactivate a logical volume"), |
| 1002 |
&object, &daemon, &caller_uid)) |
| 1003 |
goto out; |
| 1004 |
|
| 1005 |
group_object = udisks_linux_logical_volume_object_get_volume_group (object); |
| 1006 |
data.vg_name = udisks_linux_volume_group_object_get_name (group_object); |
| 1007 |
data.lv_name = udisks_linux_logical_volume_object_get_name (object); |
| 1008 |
|
| 1009 |
if (!udisks_daemon_launch_threaded_job_sync (daemon, |
| 1010 |
UDISKS_OBJECT (object), |
| 1011 |
"lvm-lvol-deactivate", |
| 1012 |
caller_uid, |
| 1013 |
FALSE, |
| 1014 |
lvdeactivate_job_func, |
| 1015 |
&data, |
| 1016 |
NULL, /* user_data_free_func */ |
| 1017 |
NULL, /* GCancellable */ |
| 1018 |
&error)) |
| 1019 |
{ |
| 1020 |
g_dbus_method_invocation_return_error (invocation, |
| 1021 |
UDISKS_ERROR, |
| 1022 |
UDISKS_ERROR_FAILED, |
| 1023 |
"Error deactivating logical volume: %s", |
| 1024 |
error->message); |
| 1025 |
g_clear_error (&error); |
| 1026 |
goto out; |
| 1027 |
} |
| 1028 |
|
| 1029 |
if (! udisks_daemon_wait_for_object_to_disappear_sync (daemon, |
| 1030 |
wait_for_logical_volume_block_object, |
| 1031 |
object, |
| 1032 |
NULL, |
| 1033 |
UDISKS_DEFAULT_WAIT_TIMEOUT, |
| 1034 |
&error)) |
| 1035 |
{ |
| 1036 |
g_prefix_error (&error, |
| 1037 |
"Error waiting for block object to disappear after deactivating '%s': ", |
| 1038 |
udisks_logical_volume_get_name (_volume)); |
| 1039 |
g_dbus_method_invocation_take_error (invocation, error); |
| 1040 |
goto out; |
| 1041 |
} |
| 1042 |
|
| 1043 |
udisks_logical_volume_complete_deactivate (_volume, invocation); |
| 1044 |
|
| 1045 |
out: |
| 1046 |
g_clear_object (&object); |
| 1047 |
return TRUE; |
| 1048 |
} |
| 1049 |
|
| 1050 |
/* ---------------------------------------------------------------------------------------------------- */ |
| 1051 |
|
| 1052 |
static gboolean |
| 1053 |
handle_create_snapshot (UDisksLogicalVolume *_volume, |
| 1054 |
GDBusMethodInvocation *invocation, |
| 1055 |
const gchar *name, |
| 1056 |
guint64 size, |
| 1057 |
GVariant *options) |
| 1058 |
{ |
| 1059 |
GError *error = NULL; |
| 1060 |
UDisksLinuxLogicalVolume *volume = UDISKS_LINUX_LOGICAL_VOLUME (_volume); |
| 1061 |
UDisksLinuxLogicalVolumeObject *object = NULL; |
| 1062 |
UDisksDaemon *daemon; |
| 1063 |
uid_t caller_uid; |
| 1064 |
UDisksLinuxVolumeGroupObject *group_object; |
| 1065 |
const gchar *lv_objpath = NULL; |
| 1066 |
LVJobData data = {0,}; |
| 1067 |
|
| 1068 |
if (!common_setup (volume, invocation, options, |
| 1069 |
N_("Authentication is required to create a snapshot of a logical volume"), |
| 1070 |
&object, &daemon, &caller_uid)) |
| 1071 |
goto out; |
| 1072 |
|
| 1073 |
group_object = udisks_linux_logical_volume_object_get_volume_group (object); |
| 1074 |
data.vg_name = udisks_linux_volume_group_object_get_name (group_object); |
| 1075 |
data.lv_name = udisks_linux_logical_volume_object_get_name (object); |
| 1076 |
data.new_lv_name = name; |
| 1077 |
data.new_lv_size = size; |
| 1078 |
|
| 1079 |
if (!udisks_daemon_launch_threaded_job_sync (daemon, |
| 1080 |
UDISKS_OBJECT (object), |
| 1081 |
"lvm-lvol-snapshot", |
| 1082 |
caller_uid, |
| 1083 |
FALSE, |
| 1084 |
lvsnapshot_create_job_func, |
| 1085 |
&data, |
| 1086 |
NULL, /* user_data_free_func */ |
| 1087 |
NULL, /* GCancellable */ |
| 1088 |
&error)) |
| 1089 |
{ |
| 1090 |
g_dbus_method_invocation_return_error (invocation, |
| 1091 |
UDISKS_ERROR, |
| 1092 |
UDISKS_ERROR_FAILED, |
| 1093 |
"Error creating snapshot: %s", |
| 1094 |
error->message); |
| 1095 |
g_clear_error (&error); |
| 1096 |
goto out; |
| 1097 |
} |
| 1098 |
|
| 1099 |
lv_objpath = wait_for_logical_volume_path (group_object, name, &error); |
| 1100 |
if (lv_objpath == NULL) |
| 1101 |
{ |
| 1102 |
g_prefix_error (&error, |
| 1103 |
"Error waiting for logical volume object for '%s': ", |
| 1104 |
name); |
| 1105 |
g_dbus_method_invocation_take_error (invocation, error); |
| 1106 |
goto out; |
| 1107 |
} |
| 1108 |
|
| 1109 |
udisks_logical_volume_complete_create_snapshot (_volume, invocation, lv_objpath); |
| 1110 |
|
| 1111 |
out: |
| 1112 |
g_clear_object (&object); |
| 1113 |
return TRUE; |
| 1114 |
} |
| 1115 |
|
| 1116 |
static gboolean |
| 1117 |
handle_cache_attach (UDisksLogicalVolume *volume_, |
| 1118 |
GDBusMethodInvocation *invocation, |
| 1119 |
const gchar *cache_name, |
| 1120 |
GVariant *options) |
| 1121 |
{ |
| 1122 |
GError *error = NULL; |
| 1123 |
UDisksLinuxLogicalVolume *volume = UDISKS_LINUX_LOGICAL_VOLUME (volume_); |
| 1124 |
UDisksLinuxLogicalVolumeObject *object = NULL; |
| 1125 |
UDisksDaemon *daemon; |
| 1126 |
uid_t caller_uid; |
| 1127 |
UDisksLinuxVolumeGroupObject *group_object; |
| 1128 |
LVJobData data = {0,}; |
| 1129 |
|
| 1130 |
if (!common_setup (volume, invocation, options, |
| 1131 |
N_("Authentication is required to convert logical volume to cache"), |
| 1132 |
&object, &daemon, &caller_uid)) |
| 1133 |
goto out; |
| 1134 |
|
| 1135 |
group_object = udisks_linux_logical_volume_object_get_volume_group (object); |
| 1136 |
data.vg_name = udisks_linux_volume_group_object_get_name (group_object); |
| 1137 |
data.lv_name = udisks_linux_logical_volume_object_get_name (object); |
| 1138 |
data.pool_name = cache_name; |
| 1139 |
|
| 1140 |
if (!udisks_daemon_launch_threaded_job_sync (daemon, |
| 1141 |
UDISKS_OBJECT (object), |
| 1142 |
"lvm-lv-make-cache", |
| 1143 |
caller_uid, |
| 1144 |
FALSE, |
| 1145 |
lvcache_attach_job_func, |
| 1146 |
&data, |
| 1147 |
NULL, /* user_data_free_func */ |
| 1148 |
NULL, /* GCancellable */ |
| 1149 |
&error)) |
| 1150 |
{ |
| 1151 |
g_dbus_method_invocation_return_error (invocation, |
| 1152 |
UDISKS_ERROR, |
| 1153 |
UDISKS_ERROR_FAILED, |
| 1154 |
N_("Error converting volume: %s"), |
| 1155 |
error->message); |
| 1156 |
g_clear_error (&error); |
| 1157 |
goto out; |
| 1158 |
} |
| 1159 |
|
| 1160 |
udisks_logical_volume_complete_cache_attach (volume_, invocation); |
| 1161 |
out: |
| 1162 |
g_clear_object (&object); |
| 1163 |
|
| 1164 |
return TRUE; |
| 1165 |
} |
| 1166 |
|
| 1167 |
|
| 1168 |
static gboolean |
| 1169 |
handle_cache_detach_or_split (UDisksLogicalVolume *volume_, |
| 1170 |
GDBusMethodInvocation *invocation, |
| 1171 |
GVariant *options, |
| 1172 |
gboolean destroy) |
| 1173 |
{ |
| 1174 |
GError *error = NULL; |
| 1175 |
UDisksLinuxLogicalVolume *volume = UDISKS_LINUX_LOGICAL_VOLUME (volume_); |
| 1176 |
UDisksLinuxLogicalVolumeObject *object = NULL; |
| 1177 |
UDisksDaemon *daemon; |
| 1178 |
uid_t caller_uid; |
| 1179 |
UDisksLinuxVolumeGroupObject *group_object; |
| 1180 |
LVJobData data = {0,}; |
| 1181 |
|
| 1182 |
if (!common_setup (volume, invocation, options, |
| 1183 |
N_("Authentication is required to split cache pool LV off of a cache LV"), |
| 1184 |
&object, &daemon, &caller_uid)) |
| 1185 |
goto out; |
| 1186 |
|
| 1187 |
group_object = udisks_linux_logical_volume_object_get_volume_group (object); |
| 1188 |
data.vg_name = udisks_linux_volume_group_object_get_name (group_object); |
| 1189 |
data.lv_name = udisks_linux_logical_volume_object_get_name (object); |
| 1190 |
data.destroy = destroy; |
| 1191 |
|
| 1192 |
if (!udisks_daemon_launch_threaded_job_sync (daemon, |
| 1193 |
UDISKS_OBJECT (object), |
| 1194 |
"lvm-lv-split-cache", |
| 1195 |
caller_uid, |
| 1196 |
FALSE, |
| 1197 |
lvcache_detach_job_func, |
| 1198 |
&data, |
| 1199 |
NULL, /* user_data_free_func */ |
| 1200 |
NULL, /* GCancellable */ |
| 1201 |
&error)) |
| 1202 |
{ |
| 1203 |
g_dbus_method_invocation_return_error (invocation, |
| 1204 |
UDISKS_ERROR, |
| 1205 |
UDISKS_ERROR_FAILED, |
| 1206 |
N_("Error converting volume: %s"), |
| 1207 |
error->message); |
| 1208 |
g_clear_error (&error); |
| 1209 |
goto out; |
| 1210 |
} |
| 1211 |
|
| 1212 |
udisks_logical_volume_complete_cache_split (volume_, invocation); |
| 1213 |
out: |
| 1214 |
g_clear_object (&object); |
| 1215 |
|
| 1216 |
return TRUE; |
| 1217 |
} |
| 1218 |
|
| 1219 |
static gboolean |
| 1220 |
handle_cache_split (UDisksLogicalVolume *volume_, |
| 1221 |
GDBusMethodInvocation *invocation, |
| 1222 |
GVariant *options) |
| 1223 |
{ |
| 1224 |
return handle_cache_detach_or_split(volume_, invocation, options, FALSE); |
| 1225 |
} |
| 1226 |
|
| 1227 |
static gboolean |
| 1228 |
handle_cache_detach (UDisksLogicalVolume *volume_, |
| 1229 |
GDBusMethodInvocation *invocation, |
| 1230 |
GVariant *options) |
| 1231 |
{ |
| 1232 |
return handle_cache_detach_or_split(volume_, invocation, options, TRUE); |
| 1233 |
} |
| 1234 |
|
| 1235 |
/* ---------------------------------------------------------------------------------------------------- */ |
| 1236 |
|
| 1237 |
static void |
| 1238 |
logical_volume_iface_init (UDisksLogicalVolumeIface *iface) |
| 1239 |
{ |
| 1240 |
iface->handle_delete = handle_delete; |
| 1241 |
iface->handle_rename = handle_rename; |
| 1242 |
iface->handle_resize = handle_resize; |
| 1243 |
iface->handle_repair = handle_repair; |
| 1244 |
iface->handle_activate = handle_activate; |
| 1245 |
iface->handle_deactivate = handle_deactivate; |
| 1246 |
iface->handle_create_snapshot = handle_create_snapshot; |
| 1247 |
|
| 1248 |
iface->handle_cache_attach = handle_cache_attach; |
| 1249 |
iface->handle_cache_split = handle_cache_split; |
| 1250 |
iface->handle_cache_detach = handle_cache_detach; |
| 1251 |
} |