diff options
author | David Zeuthen <davidz@redhat.com> | 2010-10-06 16:06:55 -0400 |
---|---|---|
committer | David Zeuthen <davidz@redhat.com> | 2010-10-06 16:06:55 -0400 |
commit | e4665237fde5efed14cacc8a6986c6a9bf00a410 (patch) | |
tree | 341b3d9d394299065a7599318dde4c10788e3768 | |
parent | c83ade0d8bcac48f843abefa5a7a6a8cc093ec86 (diff) |
Handle multiple mount points
Signed-off-by: David Zeuthen <davidz@redhat.com>
-rw-r--r-- | doc/stc-sections.txt | 2 | ||||
-rw-r--r-- | stc/stc.c | 23 | ||||
-rw-r--r-- | stc/stcenums.h | 4 | ||||
-rw-r--r-- | stc/stcitem.c | 91 | ||||
-rw-r--r-- | stc/stcitem.h | 2 |
5 files changed, 73 insertions, 49 deletions
diff --git a/doc/stc-sections.txt b/doc/stc-sections.txt index 4fecd5b..2de9a1a 100644 --- a/doc/stc-sections.txt +++ b/doc/stc-sections.txt @@ -31,7 +31,7 @@ stc_item_get_option_keys stc_item_get_dependencies stc_item_get_state stc_item_get_device -stc_item_get_mount_path +stc_item_get_mount_paths stc_item_get_slave_devices stc_item_start_sync stc_item_stop_sync @@ -289,7 +289,7 @@ handle_command_list (gint *argc, const gchar *const *deps; const gchar *const *slave_devices; const gchar *device; - const gchar *mount_path; + const gchar *const *mount_paths; type = stc_item_get_item_type (item); id = stc_item_get_id (item); @@ -394,7 +394,7 @@ handle_command_list (gint *argc, slave_devices = stc_item_get_slave_devices (item); device = stc_item_get_device (item); - mount_path = stc_item_get_mount_path (item); + mount_paths = stc_item_get_mount_paths (item); if (slave_devices != NULL) { g_print (" %sSlave Devices:%s ", @@ -422,15 +422,22 @@ handle_command_list (gint *argc, device, _color_get (_COLOR_RESET)); } - if (mount_path != NULL) + if (mount_paths != NULL) { - g_print (" %sMount Path:%s %s%s%s%s\n", + g_print (" %sMount Paths:%s ", _color_get (_COLOR_FG_WHITE), - _color_get (_COLOR_RESET), - _color_get (_COLOR_FG_YELLOW), - _color_get (_COLOR_BOLD_ON), - mount_path, _color_get (_COLOR_RESET)); + for (n = 0; mount_paths[n] != NULL; n++) + { + if (n != 0) + g_print ("\n "); + g_print ("%s%s%s%s", + _color_get (_COLOR_FG_YELLOW), + _color_get (_COLOR_BOLD_ON), + mount_paths[n], + _color_get (_COLOR_RESET)); + } + g_print ("\n"); } g_print ("\n"); diff --git a/stc/stcenums.h b/stc/stcenums.h index 2faaac0..0e8a97c 100644 --- a/stc/stcenums.h +++ b/stc/stcenums.h @@ -70,8 +70,8 @@ typedef enum /** * StcItemState: * @STC_ITEM_STATE_NOT_STARTED: The object or one of its dependencies has not been started and cannot be started at this time. - * @STC_ITEM_STATE_CAN_START_DEGRADED: Like %STC_ITEM_STATE_CAN_START but the object will be started degraded. - * @STC_ITEM_STATE_CAN_START: The object is not running but it can be started (e.g. all requisite objects are present and all dependencies are fulfilled). + * @STC_ITEM_STATE_CAN_START_DEGRADED: Like %STC_ITEM_STATE_CAN_START but the object (or one of its dependencies) will be started degraded. + * @STC_ITEM_STATE_CAN_START: The object is not currently running but it is possible to start it. * @STC_ITEM_STATE_STARTED: The object has been started. * * Enumeration describing the current state of the object described by a #StcItem. diff --git a/stc/stcitem.c b/stc/stcitem.c index fc9a96c..fe18bee 100644 --- a/stc/stcitem.c +++ b/stc/stcitem.c @@ -71,7 +71,7 @@ struct _StcItem StcItemState state; gchar **slave_devices; gchar *device; - gchar *mount_path; + gchar **mount_paths; /* private */ gchar *sort_key; @@ -118,7 +118,7 @@ stc_item_finalize (GObject *object) g_strfreev (item->slave_devices); g_free (item->device); - g_free (item->mount_path); + g_strfreev (item->mount_paths); if (G_OBJECT_CLASS (stc_item_parent_class)->finalize) G_OBJECT_CLASS (stc_item_parent_class)->finalize (object); @@ -364,19 +364,19 @@ _g_udev_client_query_by_property (GUdevClient *client, static GUdevDevice * _stc_item_filesystem_get_device (StcItem *item, - gchar **out_mount_path) + gchar ***out_mount_paths) { GUdevDevice *ret; GUdevDevice *device; GList *devices; GList *l; - gchar *mount_path; + gchar **mount_paths; g_return_val_if_fail (STC_IS_ITEM (item), NULL); g_return_val_if_fail (item->type == STC_ITEM_TYPE_FILESYSTEM, NULL); ret = NULL; - mount_path = NULL; + mount_paths = NULL; if (g_str_has_prefix (item->target, "Device=")) { @@ -439,22 +439,24 @@ _stc_item_filesystem_get_device (StcItem *item, g_udev_device_get_device_number (device)); if (mounts != NULL) { + GPtrArray *p; + p = g_ptr_array_new (); for (l = mounts; l != NULL; l = l->next) { _StcMount *mount = _STC_MOUNT (l->data); - /* we only return the first mount path right now */ - mount_path = g_strdup (_stc_mount_get_mount_path (mount)); - break; + g_ptr_array_add (p, g_strdup (_stc_mount_get_mount_path (mount))); } + g_ptr_array_add (p, NULL); + mount_paths = (gchar **) g_ptr_array_free (p, FALSE); } g_list_foreach (mounts, (GFunc) g_object_unref, NULL); g_list_free (mounts); } - if (out_mount_path != NULL) - *out_mount_path = mount_path; + if (out_mount_paths != NULL) + *out_mount_paths = mount_paths; else - g_free (mount_path); + g_strfreev (mount_paths); return ret; } @@ -567,39 +569,51 @@ _stc_item_mdraid_get_devices (StcItem *item, /* ---------------------------------------------------------------------------------------------------- */ +static gboolean +_strv_has_str (gchar **strv, + const gchar *str) +{ + guint n; + g_return_val_if_fail (str != NULL, FALSE); + if (strv == NULL) + return FALSE; + for (n = 0; strv[n] != NULL; n++) + if (g_strcmp0 (strv[n], str) == 0) + return TRUE; + return FALSE; +} + static StcItemState _stc_item_update_state_filesystem (StcItem *item) { StcItemState ret; GUdevDevice *device; - gchar *mount_path; + gchar **mount_paths; ret = STC_ITEM_STATE_NOT_STARTED; g_free (item->device); item->device = NULL; - g_free (item->mount_path); - item->mount_path = NULL; + g_strfreev (item->mount_paths); + item->mount_paths = NULL; - device = _stc_item_filesystem_get_device (item, &mount_path); + device = _stc_item_filesystem_get_device (item, &mount_paths); if (device != NULL) { - ret = STC_ITEM_STATE_CAN_START; item->device = g_strdup (g_udev_device_get_device_file (device)); - if (mount_path != NULL) + if (mount_paths != NULL) { const gchar *desired_mount_path; desired_mount_path = g_hash_table_lookup (item->options, "Filesystem:mount_path"); g_assert (desired_mount_path != NULL); - if (g_strcmp0 (desired_mount_path, mount_path) == 0) + if (_strv_has_str (mount_paths, desired_mount_path)) { - item->mount_path = g_strdup (mount_path); ret = STC_ITEM_STATE_STARTED; } - g_free (mount_path); + item->mount_paths = mount_paths; /* adopt */ } g_object_unref (device); @@ -1004,11 +1018,11 @@ stc_item_get_device (StcItem *item) return item->device; } -const gchar * -stc_item_get_mount_path (StcItem *item) +const gchar *const * +stc_item_get_mount_paths (StcItem *item) { g_return_val_if_fail (STC_IS_ITEM (item), NULL); - return item->mount_path; + return (const gchar *const *) item->mount_paths; } /* ---------------------------------------------------------------------------------------------------- */ @@ -1595,14 +1609,14 @@ _stc_item_start_filesystem (StcItem *item, GError **error) { GUdevDevice *device; - gchar *mount_path; + gchar **mount_paths; gboolean ret; ret = FALSE; - mount_path = NULL; + mount_paths = NULL; device = NULL; - device = _stc_item_filesystem_get_device (item, &mount_path); + device = _stc_item_filesystem_get_device (item, &mount_paths); if (device != NULL) { @@ -1613,15 +1627,19 @@ _stc_item_start_filesystem (StcItem *item, gchar *q_device; gchar *q_options; gchar *command_line; + const gchar *desired_mount_path; + + desired_mount_path = g_hash_table_lookup (item->options, "Filesystem:mount_path"); + g_assert (desired_mount_path != NULL); - if (mount_path != NULL) + if (mount_paths != NULL && _strv_has_str (mount_paths, desired_mount_path)) { g_set_error (error, STC_ERROR, STC_ERROR_FAILED, "Device %s is already mounted at %s", g_udev_device_get_device_file (device), - mount_path); + desired_mount_path); goto out; } @@ -1671,7 +1689,7 @@ _stc_item_start_filesystem (StcItem *item, out: if (device != NULL) g_object_unref (device); - g_free (mount_path); + g_strfreev (mount_paths); return ret; } @@ -2021,11 +2039,11 @@ _stc_item_stop_filesystem (StcItem *item, { gboolean ret; GUdevDevice *device; - gchar *mount_path; + gchar **mount_paths; ret = FALSE; - device = _stc_item_filesystem_get_device (item, &mount_path); + device = _stc_item_filesystem_get_device (item, &mount_paths); if (device != NULL) { const gchar *opt_mount_path; @@ -2033,12 +2051,12 @@ _stc_item_stop_filesystem (StcItem *item, opt_mount_path = g_hash_table_lookup (item->options, "Filesystem:mount_path"); g_assert (opt_mount_path != NULL); - if (g_strcmp0 (opt_mount_path, mount_path) == 0) + if (_strv_has_str (mount_paths, opt_mount_path)) { gchar *q_mount_path; gchar *command_line; - q_mount_path = g_shell_quote (mount_path); + q_mount_path = g_shell_quote (opt_mount_path); command_line = g_strdup_printf ("umount %s", q_mount_path); g_free (q_mount_path); @@ -2057,15 +2075,14 @@ _stc_item_stop_filesystem (StcItem *item, g_set_error (error, STC_ERROR, STC_ERROR_FAILED, - "Device is mounted at %s but Filesystem:mount_path says %s", - mount_path, + "Device is not mounted at %s", opt_mount_path); g_object_unref (device); - g_free (mount_path); + g_strfreev (mount_paths); goto out; } g_object_unref (device); - g_free (mount_path); + g_strfreev (mount_paths); } else { diff --git a/stc/stcitem.h b/stc/stcitem.h index 4422b1f..acf45ee 100644 --- a/stc/stcitem.h +++ b/stc/stcitem.h @@ -48,7 +48,7 @@ const gchar* const *stc_item_get_dependencies (StcItem *item); StcItemState stc_item_get_state (StcItem *item); const gchar* const *stc_item_get_slave_devices (StcItem *item); const gchar *stc_item_get_device (StcItem *item); -const gchar *stc_item_get_mount_path (StcItem *item); +const gchar* const *stc_item_get_mount_paths (StcItem *item); gboolean stc_item_start_sync (StcItem *item, StcOperation *operation, |