static gboolean handle_delete (CockpitStorageMDRaid *object, GDBusMethodInvocation *invocation) { StorageMDRaid *mdraid = STORAGE_MDRAID(object); StorageProvider *provider = storage_object_get_provider (mdraid->object); UDisksClient *udisks_client = storage_provider_get_udisks_client (provider); gs_unref_object UDisksBlock *block = NULL; GList *members = NULL; GError *error = NULL; /* Delete is Stop followed by wiping of all member devices. */ block = udisks_client_get_block_for_mdraid (udisks_client, mdraid->udisks_mdraid); if (block) { if (!storage_cleanup_block (provider, block, &error)) goto out; } GVariantBuilder options; g_variant_builder_init (&options, G_VARIANT_TYPE("a{sv}")); if (!udisks_mdraid_call_stop_sync (mdraid->udisks_mdraid, g_variant_builder_end (&options), NULL, &error)) goto out; members = udisks_client_get_members_for_mdraid (udisks_client, mdraid->udisks_mdraid); for (GList *m = members; m; m = m->next) { UDisksBlock *block = m->data; GVariantBuilder options; g_variant_builder_init (&options, G_VARIANT_TYPE("a{sv}")); udisks_block_call_format_sync (block, "empty", g_variant_builder_end (&options), NULL, error ? NULL : &error); } out: if (error) { g_dbus_error_strip_remote_error (error); g_dbus_method_invocation_return_error (invocation, COCKPIT_ERROR, COCKPIT_ERROR_FAILED, "%s", error->message); } else cockpit_storage_mdraid_complete_stop (object, invocation); g_list_free_full (members, g_object_unref); g_clear_error (&error); return TRUE; }
static void start_format_and_configure_block (StorageProvider *provider, UDisksBlock *block, GDBusMethodInvocation *invocation, const gchar *type, const gchar *erase, const gchar *label, const gchar *passphrase, const gchar *mount_point, const gchar *mount_options, const gchar *crypto_passphrase, const gchar *crypto_options) { GError *error = NULL; if (!storage_cleanup_block (provider, block, &error)) { g_dbus_error_strip_remote_error (error); g_dbus_method_invocation_return_error (invocation, COCKPIT_ERROR, COCKPIT_ERROR_FAILED, "%s", error->message); g_error_free (error); return; } FormatData *data = g_new0(FormatData, 1); data->block = g_object_ref (block); data->invocation = g_object_ref (invocation); data->mount_point = g_strdup (mount_point); data->mount_options = g_strdup (mount_options); data->crypto_passphrase = g_strdup (crypto_passphrase); data->crypto_options = g_strdup (crypto_options); data->udisks_object_manager = udisks_client_get_object_manager (storage_provider_get_udisks_client (provider)); data->object_added_handler_id = g_signal_connect (data->udisks_object_manager, "object-added", G_CALLBACK (on_udisks_object_added), data); GVariantBuilder options; g_variant_builder_init (&options, G_VARIANT_TYPE("a{sv}")); if (erase && strcmp (erase, "no") != 0) g_variant_builder_add (&options, "{sv}", "erase", g_variant_new_string (erase)); if (label && *label) g_variant_builder_add (&options, "{sv}", "label", g_variant_new_string (label)); if (passphrase && *passphrase) g_variant_builder_add (&options, "{sv}", "encrypt.passphrase", g_variant_new_string (passphrase)); udisks_block_call_format (block, type, g_variant_builder_end (&options), NULL, on_format_done, data); }
static gboolean handle_delete_partition (CockpitStorageBlock *object, GDBusMethodInvocation *invocation) { StorageBlock *block = STORAGE_BLOCK(object); StorageProvider *provider = storage_object_get_provider (block->object); GError *error = NULL; if (!auth_check_sender_role (invocation, COCKPIT_ROLE_STORAGE_ADMIN)) return TRUE; UDisksObject *udisks_object = (UDisksObject *) g_dbus_interface_get_object(G_DBUS_INTERFACE (block->udisks_block)); if (udisks_object == NULL) { g_dbus_method_invocation_return_error (invocation, COCKPIT_ERROR, COCKPIT_ERROR_FAILED, "No object!?"); g_error_free (error); return TRUE; } UDisksPartition *part = udisks_object_peek_partition (udisks_object); if (part == NULL) { g_dbus_method_invocation_return_error (invocation, COCKPIT_ERROR, COCKPIT_ERROR_FAILED, "Block device is not a partition"); g_error_free (error); return TRUE; } if (!storage_cleanup_block (provider, block->udisks_block, &error) || !udisks_partition_call_delete_sync (part, g_variant_new ("a{sv}", NULL), NULL, &error)) { g_dbus_error_strip_remote_error (error); g_dbus_method_invocation_return_error (invocation, COCKPIT_ERROR, COCKPIT_ERROR_FAILED, "%s", error->message); g_error_free (error); return TRUE; } cockpit_storage_block_complete_delete_partition (object, invocation); return TRUE; }