示例#1
0
void
storage_volume_group_update_block (StorageVolumeGroup *self,
                                   StorageBlock *block)
{

  GUdevDevice *device;
  StorageLogicalVolume *volume;
  const gchar *block_vg_name;
  const gchar *block_lv_name;
  GVariant *pv_info;

  device = storage_block_get_udev (block);
  if (device)
    {
      block_vg_name = g_udev_device_get_property (device, "DM_VG_NAME");
      block_lv_name = g_udev_device_get_property (device, "DM_LV_NAME");

      if (g_strcmp0 (block_vg_name, storage_volume_group_get_name (self)) == 0)
        {
          volume = g_hash_table_lookup (self->logical_volumes, block_lv_name);
          storage_block_update_lv (block, volume);
        }
      g_object_unref (device);
    }

  pv_info = g_hash_table_lookup (self->physical_volumes, storage_block_get_device (block));
  if (!pv_info)
    {
      const gchar *const *symlinks;
      int i;
      symlinks = storage_block_get_symlinks (block);
      for (i = 0; symlinks[i]; i++)
        {
          pv_info = g_hash_table_lookup (self->physical_volumes, symlinks[i]);
          if (pv_info)
            break;
        }
    }

  if (pv_info)
    {
      storage_block_update_pv (block, self, pv_info);
    }
  else
    {
      LvmPhysicalVolumeBlock *pv = storage_block_get_physical_volume_block (block);
      if (pv && g_strcmp0 (lvm_physical_volume_block_get_volume_group (pv),
                           storage_volume_group_get_object_path (self)) == 0)
        storage_block_update_pv (block, NULL, NULL);
    }
}
示例#2
0
static gboolean
handle_delete (LvmVolumeGroup *group,
               GDBusMethodInvocation *invocation,
               gboolean arg_wipe,
               GVariant *arg_options)
{
  StorageVolumeGroup *self = STORAGE_VOLUME_GROUP (group);
  VolumeGroupDeleteJobData *data;
  StorageDaemon *daemon;
  StorageJob *job;
  GList *l;

  daemon = storage_daemon_get ();

  data = g_new0 (VolumeGroupDeleteJobData, 1);
  data->vgname = g_strdup (storage_volume_group_get_name (self));

  /* Find physical volumes to wipe. */
  if (arg_wipe)
    {
      GPtrArray *devices = g_ptr_array_new ();
      GList *blocks = storage_manager_get_blocks (storage_daemon_get_manager (daemon));
      for (l = blocks; l; l = l->next)
        {
          LvmPhysicalVolumeBlock *physical_volume;
          physical_volume = storage_block_get_physical_volume_block (l->data);
          if (physical_volume
              && g_strcmp0 (lvm_physical_volume_block_get_volume_group (physical_volume),
                            storage_volume_group_get_object_path (self)) == 0)
            g_ptr_array_add (devices, g_strdup (storage_block_get_device (l->data)));
        }
      g_list_free_full (blocks, g_object_unref);
      g_ptr_array_add (devices, NULL);
      data->devices = (gchar **)g_ptr_array_free (devices, FALSE);
    }

  job = storage_daemon_launch_threaded_job (daemon, self,
                                            "lvm-vg-delete",
                                            storage_invocation_get_caller_uid (invocation),
                                            volume_group_delete_job_thread,
                                            data,
                                            volume_group_delete_job_free,
                                            NULL);

  g_signal_connect_data (job, "completed", G_CALLBACK (on_delete_complete),
                         g_object_ref (invocation), (GClosureNotify)g_object_unref, 0);

  return TRUE;
}
示例#3
0
void
storage_block_update (StorageBlock *block)
{
  CockpitStorageBlock *iface = COCKPIT_STORAGE_BLOCK (block);
  StorageProvider *provider;
  UDisksClient *udisks_client;
  UDisksObject *udisks_object;
  UDisksBlock *udisks_block;
  UDisksPartition *udisks_partition = NULL;
  UDisksPartitionTable *udisks_partition_table = NULL;
  UDisksFilesystem *udisks_filesystem = NULL;

  provider = storage_object_get_provider (block->object);
  udisks_client = storage_provider_get_udisks_client (provider);
  udisks_block = block->udisks_block;
  udisks_object = (UDisksObject *)g_dbus_interface_get_object (G_DBUS_INTERFACE (udisks_block));
  if (udisks_object != NULL)
    {
      udisks_partition = udisks_object_peek_partition (udisks_object);
      udisks_partition_table = udisks_object_peek_partition_table (udisks_object);
      udisks_filesystem = udisks_object_peek_filesystem (udisks_object);
    }

  {
    gs_free gchar *d =
      g_filename_display_name (udisks_block_get_preferred_device (udisks_block));
    cockpit_storage_block_set_device (iface, d);
  }

  cockpit_storage_block_set_size       (iface, udisks_block_get_size (udisks_block));
  cockpit_storage_block_set_id_usage   (iface, udisks_block_get_id_usage   (udisks_block));
  cockpit_storage_block_set_id_type    (iface, udisks_block_get_id_type    (udisks_block));
  cockpit_storage_block_set_id_version (iface, udisks_block_get_id_version (udisks_block));
  cockpit_storage_block_set_id_label   (iface, udisks_block_get_id_label   (udisks_block));
  cockpit_storage_block_set_id_uuid    (iface, udisks_block_get_id_uuid    (udisks_block));

  cockpit_storage_block_set_hint_ignore (iface, udisks_block_get_hint_ignore (udisks_block));

  if (udisks_partition == NULL)
    {
      cockpit_storage_block_set_partition_number (iface, 0);
      cockpit_storage_block_set_partition_table (iface, "/");
    }
  else
    {
      UDisksPartitionTable *table_for_partition;
      const gchar *objpath = "/";
      GDBusObject *o;
      UDisksBlock *b;
      StorageObject *so;

      table_for_partition = udisks_client_get_partition_table (udisks_client, udisks_partition);
      if (table_for_partition != NULL)
        {
          o = g_dbus_interface_get_object (G_DBUS_INTERFACE (table_for_partition));
          if (o != NULL)
            {
              b = udisks_object_peek_block (UDISKS_OBJECT (o));
              if (b != NULL)
                {
                  so = storage_provider_lookup_for_udisks_block (provider, b);
                  if (so != NULL)
                    {
                      objpath = g_dbus_object_get_object_path (G_DBUS_OBJECT (so));
                    }
                }
            }
        }
      cockpit_storage_block_set_partition_table (iface, objpath);
      cockpit_storage_block_set_partition_number (iface, udisks_partition_get_number (udisks_partition));
    }

  GVariantBuilder partitions;
  g_variant_builder_init (&partitions, G_VARIANT_TYPE ("a(otts)"));

  if (udisks_partition_table != NULL)
    {
      GList *ps, *l;
      ps = udisks_client_get_partitions (udisks_client, udisks_partition_table);
      for (l = ps; l != NULL; l = l->next)
        {
          UDisksPartition *p = UDISKS_PARTITION (l->data);
          GDBusObject *o;
          UDisksBlock *b;
          StorageObject *so;

          o = g_dbus_interface_get_object (G_DBUS_INTERFACE (p));
          if (o != NULL)
            {
              b = udisks_object_peek_block (UDISKS_OBJECT (o));
              if (b != NULL)
                {
                  so = storage_provider_lookup_for_udisks_block (provider, b);
                  if (so != NULL)
                    {
                      const gchar *type = "p";
                      if (udisks_partition_get_is_container (p))
                        type = "x";
                      else if (udisks_partition_get_is_contained (p))
                        type = "l";
                      g_variant_builder_add (&partitions, "(otts)",
                                             g_dbus_object_get_object_path (G_DBUS_OBJECT (so)),
                                             udisks_partition_get_offset (p),
                                             udisks_partition_get_size (p),
                                             type);
                    }
                }
            }
        }
      g_list_free_full (ps, g_object_unref);
      const gchar *type = udisks_partition_table_get_type_ (udisks_partition_table);
      if (type == NULL || type[0] == '\0')
        type = "unknown";
      cockpit_storage_block_set_partition_table_type (iface, type);
    }
  else
    cockpit_storage_block_set_partition_table_type (iface, "");

  cockpit_storage_block_set_partitions (iface, g_variant_builder_end (&partitions));

  cockpit_storage_block_set_drive
    (iface, storage_provider_translate_path (provider, udisks_block_get_drive (udisks_block)));
  cockpit_storage_block_set_crypto_backing_device
    (iface, storage_provider_translate_path (provider, udisks_block_get_crypto_backing_device (udisks_block)));
  cockpit_storage_block_set_mdraid
    (iface, storage_provider_translate_path (provider, udisks_block_get_mdraid (udisks_block)));
  cockpit_storage_block_set_mdraid_member
    (iface, storage_provider_translate_path (provider, udisks_block_get_mdraid_member (udisks_block)));

  if (udisks_filesystem)
    {
      const gchar *const *p = udisks_filesystem_get_mount_points (udisks_filesystem);
      gchar *u[g_strv_length ((gchar **)p) + 1];
      int i;
      for (i = 0; p[i]; i++)
        u[i] = g_filename_display_name (p[i]);
      u[i] = NULL;
      cockpit_storage_block_set_mounted_at (iface, (const gchar *const *)u);
      for (i = 0; u[i]; i++)
        g_free (u[i]);
    }

  GVariantIter iter;
  g_variant_iter_init (&iter, udisks_block_get_configuration (udisks_block));
  const gchar *type;
  GVariant *details;
  gboolean got_fstab = FALSE, got_crypttab = FALSE;
  while (g_variant_iter_next (&iter, "(&s*)", &type, &details))
    {
      if (strcmp (type, "fstab") == 0 && !got_fstab)
        {
          got_fstab = TRUE;
          const gchar *dir = variant_lookup (details, "dir");
          if (dir)
            {
              gs_free gchar *dir_display = g_filename_display_name (dir);
              cockpit_storage_block_set_mount_point (iface, dir_display);
            }
          const gchar *opts = variant_lookup (details, "opts");
          if (opts)
            {
              gs_free gchar *opts_locale = g_locale_to_utf8 (opts, -1, NULL, NULL, NULL);
              if (opts_locale)
                cockpit_storage_block_set_mount_options (iface, opts_locale);
              else
                g_warning ("Can't convert fstab options into UTF8");
            }
        }
      else if (strcmp (type, "crypttab") == 0 && !got_crypttab)
        {
          got_crypttab = TRUE;
          const gchar *opts = variant_lookup (details, "options");
          if (opts)
            {
              gs_free gchar *opts_locale = g_locale_to_utf8 (opts, -1, NULL, NULL, NULL);
              if (opts_locale)
                cockpit_storage_block_set_crypto_options (iface, opts_locale);
              else
                g_warning ("Can't convert crypttab options into UTF8");
            }
        }
      g_variant_unref (details);
    }

  /* Now the com.redhat.lvm2 overlays.  The StorageProvider makes sure
     that we are called whenever something changes about them.
   */

  LvmLogicalVolumeBlock *lv = NULL;
  LvmPhysicalVolumeBlock *pv = NULL;

  GDBusObjectManager *objman = storage_provider_get_lvm_object_manager (provider);
  GDBusObject *lvm_object =
    g_dbus_object_manager_get_object (objman,
                                      g_dbus_object_get_object_path (G_DBUS_OBJECT (udisks_object)));
  if (lvm_object)
    {
      lv = lvm_object_peek_logical_volume_block (LVM_OBJECT (lvm_object));
      pv = lvm_object_peek_physical_volume_block (LVM_OBJECT (lvm_object));
    }

  if (lv)
    {
      cockpit_storage_block_set_logical_volume
        (iface,
         storage_provider_translate_path
         (provider,
          lvm_logical_volume_block_get_logical_volume (lv)));
    }
  else
    cockpit_storage_block_set_logical_volume (iface, "/");

  if (pv)
    {
      cockpit_storage_block_set_pv_group
        (iface,
         storage_provider_translate_path (provider,
                                          lvm_physical_volume_block_get_volume_group (pv)));
      cockpit_storage_block_set_pv_size (iface,
                                         lvm_physical_volume_block_get_size (pv));
      cockpit_storage_block_set_pv_free_size (iface,
                                              lvm_physical_volume_block_get_free_size (pv));
    }
  else
    {
      cockpit_storage_block_set_pv_group (iface, "/");
      cockpit_storage_block_set_pv_size (iface, 0);
      cockpit_storage_block_set_pv_free_size (iface, 0);
    }
}