Example #1
0
static gboolean
dummy_loop_object_process_uevent (StoragedModuleObject  *module_object,
                                  const gchar           *action,
                                  StoragedLinuxDevice   *device)
{
  DummyLoopObject *object;
  GList *link;

  g_return_val_if_fail (DUMMY_IS_LOOP_OBJECT (module_object), FALSE);
  g_return_val_if_fail (device == NULL || STORAGED_IS_LINUX_DEVICE (device), FALSE);

  if (! dummy_loop_object_should_include_device (device))
    return FALSE;

  object = DUMMY_LOOP_OBJECT (module_object);

  link = NULL;
  if (device != NULL)
    link = find_link_for_sysfs_path (object, g_udev_device_get_sysfs_path (device->udev_device));
  if (g_strcmp0 (action, "remove") == 0)
    {
      if (link != NULL)
        {
          g_object_unref (STORAGED_LINUX_DEVICE (link->data));
          object->devices = g_list_delete_link (object->devices, link);
        }
      else
        {
          storaged_warning ("Object doesn't have device with sysfs path %s on remove event",
                            g_udev_device_get_sysfs_path (device->udev_device));
        }
    }
  else
    {
      if (link != NULL)
        {
          g_object_unref (STORAGED_LINUX_DEVICE (link->data));
          link->data = g_object_ref (device);
        }
      else
        {
          if (device != NULL)
            {
              object->devices = g_list_append (object->devices, g_object_ref (device));
              g_object_notify (G_OBJECT (object), "device");
            }
        }
    }

  update_iface (STORAGED_OBJECT (object), action, linux_loop_check, linux_loop_connect, linux_loop_update,
                DUMMY_TYPE_LINUX_LOOP, &object->iface_loop);

  return TRUE;
}
/**
 * storaged_linux_block_object_uevent:
 * @object: A #StoragedLinuxBlockObject.
 * @action: Uevent action or %NULL
 * @device: A new #StoragedLinuxDevice device object or %NULL if the device hasn't changed.
 *
 * Updates all information on interfaces on @object.
 */
void
storaged_linux_block_object_uevent (StoragedLinuxBlockObject *object,
                                    const gchar              *action,
                                    StoragedLinuxDevice      *device)
{
    StoragedModuleManager *module_manager;
    GHashTableIter iter;
    gpointer key;
    ModuleInterfaceEntry *entry;

    g_return_if_fail (STORAGED_IS_LINUX_BLOCK_OBJECT (object));
    g_return_if_fail (device == NULL || STORAGED_IS_LINUX_DEVICE (device));

    if (device != NULL)
    {
        g_object_unref (object->device);
        object->device = g_object_ref (device);
        g_object_notify (G_OBJECT (object), "device");
    }

    update_iface (STORAGED_OBJECT (object), action, block_device_check, block_device_connect, block_device_update,
                  STORAGED_TYPE_LINUX_BLOCK, &object->iface_block_device);
    update_iface (STORAGED_OBJECT (object), action, filesystem_check, filesystem_connect, filesystem_update,
                  STORAGED_TYPE_LINUX_FILESYSTEM, &object->iface_filesystem);
    update_iface (STORAGED_OBJECT (object), action, swapspace_check, swapspace_connect, swapspace_update,
                  STORAGED_TYPE_LINUX_SWAPSPACE, &object->iface_swapspace);
    update_iface (STORAGED_OBJECT (object), action, encrypted_check, encrypted_connect, encrypted_update,
                  STORAGED_TYPE_LINUX_ENCRYPTED, &object->iface_encrypted);
    update_iface (STORAGED_OBJECT (object), action, loop_check, loop_connect, loop_update,
                  STORAGED_TYPE_LINUX_LOOP, &object->iface_loop);
    update_iface (STORAGED_OBJECT (object), action, partition_table_check, partition_table_connect, partition_table_update,
                  STORAGED_TYPE_LINUX_PARTITION_TABLE, &object->iface_partition_table);
    update_iface (STORAGED_OBJECT (object), action, partition_check, partition_connect, partition_update,
                  STORAGED_TYPE_LINUX_PARTITION, &object->iface_partition);

    /* Attach interfaces from modules */
    module_manager = storaged_daemon_get_module_manager (object->daemon);
    if (storaged_module_manager_get_modules_available (module_manager))
    {
        ensure_module_ifaces (object, module_manager);
        g_hash_table_iter_init (&iter, object->module_ifaces);
        while (g_hash_table_iter_next (&iter, &key, (gpointer *) &entry))
        {
            update_iface (STORAGED_OBJECT (object), action, entry->has_func, entry->connect_func, entry->update_func,
                          (GType) key, &entry->interface);
        }
    }
}
/**
 * storaged_linux_drive_object_new:
 * @daemon: A #StoragedDaemon.
 * @device: The #StoragedLinuxDevice for the sysfs block device.
 *
 * Create a new drive object.
 *
 * Returns: A #StoragedLinuxDriveObject object or %NULL if @device does not represent a drive. Free with g_object_unref().
 */
StoragedLinuxDriveObject *
storaged_linux_drive_object_new (StoragedDaemon      *daemon,
                                 StoragedLinuxDevice *device)
{
    GObject *object;

    g_return_val_if_fail (STORAGED_IS_DAEMON (daemon), NULL);
    g_return_val_if_fail (STORAGED_IS_LINUX_DEVICE (device), NULL);

    object = g_object_new (STORAGED_TYPE_LINUX_DRIVE_OBJECT,
                           "daemon", daemon,
                           "device", device,
                           NULL);

    if (object != NULL)
        return STORAGED_LINUX_DRIVE_OBJECT (object);
    else
        return NULL;
}
Example #4
0
/**
 * dummy_loop_object_new:
 * @daemon: A #StoragedDaemon.
 * @device: The #StoragedLinuxDevice for the sysfs block device.
 *
 * Create a new loop object.
 *
 * Returns: A #DummyLoopObject object or %NULL if @device does not represent a loop block device. Free with g_object_unref().
 */
DummyLoopObject *
dummy_loop_object_new (StoragedDaemon      *daemon,
                       StoragedLinuxDevice *device)
{
  GObject *object;

  g_return_val_if_fail (STORAGED_IS_DAEMON (daemon), NULL);
  g_return_val_if_fail (STORAGED_IS_LINUX_DEVICE (device), NULL);

  if (! dummy_loop_object_should_include_device (device))
    return NULL;

  object = g_object_new (DUMMY_TYPE_LOOP_OBJECT,
                         "daemon", daemon,
                         "device", device,
                         NULL);

  if (object != NULL)
    return DUMMY_LOOP_OBJECT (object);
  else
    return NULL;
}
/**
 * storaged_linux_drive_object_uevent:
 * @object: A #StoragedLinuxDriveObject.
 * @action: Uevent action or %NULL
 * @device: A #StoragedLinuxDevice device object or %NULL if the device hasn't changed.
 *
 * Updates all information on interfaces on @drive.
 */
void
storaged_linux_drive_object_uevent (StoragedLinuxDriveObject *object,
                                    const gchar              *action,
                                    StoragedLinuxDevice      *device)
{
    GList *link;
    gboolean conf_changed;
    StoragedModuleManager *module_manager;
    GHashTableIter iter;
    gpointer key;
    ModuleInterfaceEntry *entry;

    g_return_if_fail (STORAGED_IS_LINUX_DRIVE_OBJECT (object));
    g_return_if_fail (device == NULL || STORAGED_IS_LINUX_DEVICE (device));

    link = NULL;
    if (device != NULL)
        link = find_link_for_sysfs_path (object, g_udev_device_get_sysfs_path (device->udev_device));
    if (g_strcmp0 (action, "remove") == 0)
    {
        if (link != NULL)
        {
            g_object_unref (STORAGED_LINUX_DEVICE (link->data));
            object->devices = g_list_delete_link (object->devices, link);
        }
        else
        {
            storaged_warning ("Drive doesn't have device with sysfs path %s on remove event",
                              device ? g_udev_device_get_sysfs_path (device->udev_device) : "(null device)");
        }
    }
    else
    {
        if (link != NULL)
        {
            g_object_unref (STORAGED_LINUX_DEVICE (link->data));
            link->data = g_object_ref (device);
        }
        else
        {
            if (device != NULL)
                object->devices = g_list_append (object->devices, g_object_ref (device));
        }
    }

    conf_changed = FALSE;
    conf_changed |= update_iface (STORAGED_OBJECT (object), action, drive_check, drive_connect, drive_update,
                                  STORAGED_TYPE_LINUX_DRIVE, &object->iface_drive);
    conf_changed |= update_iface (STORAGED_OBJECT (object), action, drive_ata_check, drive_ata_connect, drive_ata_update,
                                  STORAGED_TYPE_LINUX_DRIVE_ATA, &object->iface_drive_ata);

    /* Attach interfaces from modules */
    module_manager = storaged_daemon_get_module_manager (object->daemon);
    if (storaged_module_manager_get_modules_available (module_manager))
    {
        ensure_module_ifaces (object, module_manager);
        g_hash_table_iter_init (&iter, object->module_ifaces);
        while (g_hash_table_iter_next (&iter, &key, (gpointer *) &entry))
        {
            conf_changed |= update_iface (STORAGED_OBJECT (object), action, entry->has_func, entry->connect_func, entry->update_func,
                                          (GType) key, &entry->interface);
        }
    }

    if (conf_changed)
        apply_configuration (object);
}