static gboolean handle_set_bitmap_location (CockpitStorageMDRaid *object, GDBusMethodInvocation *invocation, const gchar *arg_value) { StorageMDRaid *mdraid = STORAGE_MDRAID(object); GError *error = NULL; if (!auth_check_sender_role (invocation, COCKPIT_ROLE_STORAGE_ADMIN)) return TRUE; GVariantBuilder options; g_variant_builder_init (&options, G_VARIANT_TYPE("a{sv}")); if (!udisks_mdraid_call_set_bitmap_location_sync (mdraid->udisks_mdraid, arg_value, g_variant_builder_end (&options), 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); } else cockpit_storage_mdraid_complete_set_bitmap_location (object, invocation); return TRUE; }
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 gboolean handle_start (CockpitStorageMDRaid *object, GDBusMethodInvocation *invocation) { StorageMDRaid *mdraid = STORAGE_MDRAID(object); GError *error = NULL; GVariantBuilder options; g_variant_builder_init (&options, G_VARIANT_TYPE("a{sv}")); g_variant_builder_add (&options, "{sv}", "start-degraded", g_variant_new_boolean (TRUE)); if (!udisks_mdraid_call_start_sync (mdraid->udisks_mdraid, g_variant_builder_end (&options), 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); } else cockpit_storage_mdraid_complete_start (object, invocation); return TRUE; }
static void on_udisks_mdraid_notify (GObject *object, GParamSpec *pspec, gpointer user_data) { StorageMDRaid *mdraid = STORAGE_MDRAID (user_data); storage_mdraid_update (mdraid); }
static gboolean handle_remove_devices (CockpitStorageMDRaid *object, GDBusMethodInvocation *invocation, const gchar *const *arg_devices) { StorageMDRaid *mdraid = STORAGE_MDRAID(object); StorageProvider *provider = storage_object_get_provider (mdraid->object); Daemon *daemon = storage_provider_get_daemon (provider); GDBusObjectManagerServer *object_manager_server = daemon_get_object_manager (daemon); GDBusObjectManager *object_manager = G_DBUS_OBJECT_MANAGER (object_manager_server); GError *error = NULL; if (!auth_check_sender_role (invocation, COCKPIT_ROLE_STORAGE_ADMIN)) return TRUE; int n_devices = 0; for (int i = 0; arg_devices[i]; i++) n_devices += 1; const gchar *udisks_devices[n_devices + 1]; for (int i = 0; arg_devices[i]; i++) { StorageObject *stobj = STORAGE_OBJECT(g_dbus_object_manager_get_object (object_manager, arg_devices[i])); UDisksBlock *block = storage_object_get_udisks_block (stobj); if (block) udisks_devices[i] = g_dbus_proxy_get_object_path (G_DBUS_PROXY(block)); else udisks_devices[i] = "XXX"; } udisks_devices[n_devices] = NULL; for (int i = 0; udisks_devices[i]; i++) { GVariantBuilder options; g_variant_builder_init (&options, G_VARIANT_TYPE("a{sv}")); g_variant_builder_add (&options, "{sv}", "wipe", g_variant_new_boolean (TRUE)); if (!udisks_mdraid_call_remove_device_sync (mdraid->udisks_mdraid, udisks_devices[i], g_variant_builder_end (&options), 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_mdraid_complete_remove_devices (object, invocation); return TRUE; }
static void storage_mdraid_finalize (GObject *object) { StorageMDRaid *mdraid = STORAGE_MDRAID (object); g_signal_handlers_disconnect_by_func (mdraid->udisks_mdraid, G_CALLBACK (on_udisks_mdraid_notify), mdraid); g_object_unref (mdraid->udisks_mdraid); G_OBJECT_CLASS (storage_mdraid_parent_class)->finalize (object); }
static void storage_mdraid_constructed (GObject *object) { StorageMDRaid *mdraid = STORAGE_MDRAID (object); mdraid->udisks_mdraid = g_object_ref (storage_object_get_udisks_mdraid (mdraid->object)); g_signal_connect (mdraid->udisks_mdraid, "notify", G_CALLBACK (on_udisks_mdraid_notify), mdraid); storage_mdraid_update (mdraid); if (G_OBJECT_CLASS (storage_mdraid_parent_class)->constructed != NULL) G_OBJECT_CLASS (storage_mdraid_parent_class)->constructed (object); }
static void storage_mdraid_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { StorageMDRaid *mdraid = STORAGE_MDRAID (object); switch (prop_id) { case PROP_OBJECT: g_value_set_object (value, mdraid->object); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; } }