summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Zeuthen <davidz@redhat.com>2010-10-07 14:43:23 -0400
committerDavid Zeuthen <davidz@redhat.com>2010-10-07 14:43:23 -0400
commit68f743407bc7ba627add70b0cd3b103a8f813690 (patch)
treed82f3ffc00aa1b0a0479a3cb5cede961deb443e8
parent53a7d2fb8553b186af3064d939b08ae1c6cde132 (diff)
Make stc(8) print information when starting/stopping items
... and also sort out slave_devices, device and mount_paths state variables. # stc start --id sekrit Passphrase needed for item sekrit_Luks of type luks (/dev/sdb2) Passphrase: Item sekrit_Luks has been started (/dev/sdb2 is unlocked as /dev/dm-0). Item sekrit has been started (/dev/dm-0 is mounted at /mnt/sekrit). # stc start --id MyRaid Item MyRaid_Raid has been started (/dev/md127 with components /dev/sdb1, /dev/mmcblk0p1). Item MyRaid has been started (/dev/md127 is mounted at /mnt/MyRaid). # stc stop --id MyRaid Item MyRaid has been stopped (/dev/md127 unmounted). Item MyRaid_Raid has been stopped (components /dev/sdb1, /dev/mmcblk0p1). # stc stop --id sekrit Item sekrit has been stopped (/dev/dm-0 unmounted). Item sekrit_Luks has been stopped (/dev/sdb2 locked). Signed-off-by: David Zeuthen <davidz@redhat.com>
-rw-r--r--doc/stc-sections.txt6
-rw-r--r--stc/stc.c173
-rw-r--r--stc/stcitem.c64
-rw-r--r--stc/stcitem.h40
-rw-r--r--stc/stcmountmonitor.c4
-rw-r--r--stc/stcmountmonitor.h1
-rw-r--r--stc/stcoperation.c72
-rw-r--r--stc/stcoperation.h4
8 files changed, 300 insertions, 64 deletions
diff --git a/doc/stc-sections.txt b/doc/stc-sections.txt
index 6229f39..c2db8f0 100644
--- a/doc/stc-sections.txt
+++ b/doc/stc-sections.txt
@@ -30,9 +30,9 @@ stc_item_get_option
stc_item_get_option_keys
stc_item_get_dependencies
stc_item_get_state
-stc_item_get_device
-stc_item_get_mount_paths
stc_item_get_slave_devices
+stc_item_get_resulting_device
+stc_item_get_resulting_mount_path
stc_item_start_sync
stc_item_stop_sync
<SUBSECTION Standard>
@@ -54,6 +54,8 @@ StcOperation
stc_operation_new
stc_operation_request_passphrase
stc_operation_may_start_degraded
+stc_operation_started
+stc_operation_stopped
<SUBSECTION Standard>
STC_TYPE_OPERATION
STC_OPERATION
diff --git a/stc/stc.c b/stc/stc.c
index 7d975c4..91e6f2d 100644
--- a/stc/stc.c
+++ b/stc/stc.c
@@ -288,8 +288,8 @@ handle_command_list (gint *argc,
const gchar *const *options;
const gchar *const *deps;
const gchar *const *slave_devices;
- const gchar *device;
- const gchar *const *mount_paths;
+ const gchar *resulting_device;
+ const gchar *resulting_mount_path;
type = stc_item_get_item_type (item);
id = stc_item_get_id (item);
@@ -393,8 +393,8 @@ handle_command_list (gint *argc,
_color_get (_COLOR_RESET));
slave_devices = stc_item_get_slave_devices (item);
- device = stc_item_get_device (item);
- mount_paths = stc_item_get_mount_paths (item);
+ resulting_device = stc_item_get_resulting_device (item);
+ resulting_mount_path = stc_item_get_resulting_mount_path (item);
if (slave_devices != NULL)
{
g_print (" %sSlave Devices:%s ",
@@ -412,32 +412,25 @@ handle_command_list (gint *argc,
}
g_print ("\n");
}
- if (device != NULL)
+ if (resulting_device != NULL)
{
g_print (" %sDevice:%s %s%s%s%s\n",
_color_get (_COLOR_FG_WHITE),
_color_get (_COLOR_RESET),
_color_get (_COLOR_FG_YELLOW),
_color_get (_COLOR_BOLD_ON),
- device,
+ resulting_device,
_color_get (_COLOR_RESET));
}
- if (mount_paths != NULL)
+ if (resulting_mount_path != NULL)
{
- g_print (" %sMount Paths:%s ",
+ g_print (" %sMount Path:%s %s%s%s%s\n",
_color_get (_COLOR_FG_WHITE),
+ _color_get (_COLOR_RESET),
+ _color_get (_COLOR_FG_YELLOW),
+ _color_get (_COLOR_BOLD_ON),
+ resulting_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");
@@ -667,6 +660,140 @@ on_request_passphrase (StcOperation *operation,
return ret;
}
+static void
+on_started (StcOperation *operation,
+ StcItem *item,
+ gpointer user_data)
+{
+ gchar *extra;
+
+ extra = NULL;
+ switch (stc_item_get_item_type (item))
+ {
+ case STC_ITEM_TYPE_FILESYSTEM:
+ {
+ const gchar *const *slave_devices = stc_item_get_slave_devices (item);
+ extra = g_strdup_printf ("%s is mounted at %s",
+ slave_devices != NULL ? slave_devices[0] : "(unknown)",
+ stc_item_get_resulting_mount_path (item));
+ }
+ break;
+
+ case STC_ITEM_TYPE_LUKS:
+ {
+ const gchar *const *slave_devices = stc_item_get_slave_devices (item);
+ extra = g_strdup_printf ("%s is unlocked as %s",
+ slave_devices != NULL ? slave_devices[0] : "(unknown)",
+ stc_item_get_resulting_device (item));
+ }
+ break;
+
+ case STC_ITEM_TYPE_RAID:
+ {
+ const gchar *const *slave_devices = stc_item_get_slave_devices (item);
+ GString *str;
+ guint n;
+ str = g_string_new (NULL);
+ g_string_append_printf (str,
+ "%s with components ",
+ stc_item_get_resulting_device (item));
+ for (n = 0; slave_devices != NULL && slave_devices[n] != NULL; n++)
+ {
+ if (n > 0)
+ g_string_append (str, ", ");
+ g_string_append (str, slave_devices[n]);
+ }
+ extra = g_string_free (str, FALSE);
+ }
+ break;
+
+ default:
+ break;
+ }
+
+ g_print ("Item %s%s%s%s has been started",
+ _color_get (_COLOR_FG_BLUE),
+ _color_get (_COLOR_BOLD_ON),
+ stc_item_get_id (item),
+ _color_get (_COLOR_RESET));
+ if (extra != NULL)
+ {
+ g_print (" (%s).\n", extra);
+ }
+ else
+ {
+ g_print (".\n");
+ }
+ g_free (extra);
+}
+
+static void
+on_stopped (StcOperation *operation,
+ StcItem *item,
+ gpointer user_data)
+{
+ gchar *extra;
+
+ extra = NULL;
+ switch (stc_item_get_item_type (item))
+ {
+ case STC_ITEM_TYPE_FILESYSTEM:
+ {
+ const gchar *const *slave_devices = stc_item_get_slave_devices (item);
+ if (slave_devices != NULL && slave_devices[0] != NULL)
+ extra = g_strdup_printf ("%s unmounted", slave_devices[0]);
+ }
+ break;
+
+ case STC_ITEM_TYPE_LUKS:
+ {
+ const gchar *const *slave_devices = stc_item_get_slave_devices (item);
+ if (slave_devices != NULL && slave_devices[0] != NULL)
+ extra = g_strdup_printf ("%s locked", slave_devices[0]);
+ }
+ break;
+
+ case STC_ITEM_TYPE_RAID:
+ {
+ const gchar *const *slave_devices = stc_item_get_slave_devices (item);
+ if (slave_devices != NULL && slave_devices[0] != NULL)
+ {
+ GString *str;
+ guint n;
+
+ str = g_string_new (NULL);
+ g_string_append (str, "components ");
+ for (n = 0; slave_devices != NULL && slave_devices[n] != NULL; n++)
+ {
+ if (n > 0)
+ g_string_append (str, ", ");
+ g_string_append (str, slave_devices[n]);
+ }
+ extra = g_string_free (str, FALSE);
+ }
+ }
+ break;
+
+ default:
+ break;
+ }
+
+ g_print ("Item %s%s%s%s has been stopped",
+ _color_get (_COLOR_FG_BLUE),
+ _color_get (_COLOR_BOLD_ON),
+ stc_item_get_id (item),
+ _color_get (_COLOR_RESET));
+ if (extra != NULL)
+ {
+ g_print (" (%s).\n", extra);
+ }
+ else
+ {
+ g_print (".\n");
+ }
+ g_free (extra);
+}
+
static const GOptionEntry command_start_entries[] =
{
@@ -807,6 +934,14 @@ handle_command_start_stop (gint *argc,
"request-passphrase",
G_CALLBACK (on_request_passphrase),
NULL);
+ g_signal_connect (operation,
+ "started",
+ G_CALLBACK (on_started),
+ NULL);
+ g_signal_connect (operation,
+ "stopped",
+ G_CALLBACK (on_stopped),
+ NULL);
if (is_start)
{
diff --git a/stc/stcitem.c b/stc/stcitem.c
index 19cea4e..2f664f1 100644
--- a/stc/stcitem.c
+++ b/stc/stcitem.c
@@ -70,8 +70,8 @@ struct _StcItem
/* current state */
StcItemState state;
gchar **slave_devices;
- gchar *device;
- gchar **mount_paths;
+ gchar *resulting_device;
+ gchar *resulting_mount_path;
/* private */
gchar *sort_key;
@@ -117,8 +117,8 @@ stc_item_finalize (GObject *object)
g_free (item->path);
g_strfreev (item->slave_devices);
- g_free (item->device);
- g_strfreev (item->mount_paths);
+ g_free (item->resulting_device);
+ g_free (item->resulting_mount_path);
if (G_OBJECT_CLASS (stc_item_parent_class)->finalize)
G_OBJECT_CLASS (stc_item_parent_class)->finalize (object);
@@ -592,17 +592,18 @@ _stc_item_update_state_filesystem (StcItem *item)
ret = STC_ITEM_STATE_NOT_STARTED;
- g_free (item->device);
- item->device = NULL;
- g_strfreev (item->mount_paths);
- item->mount_paths = NULL;
+ g_free (item->slave_devices);
+ item->slave_devices = NULL;
+ g_free (item->resulting_mount_path);
+ item->resulting_mount_path = NULL;
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));
+ item->slave_devices = g_new0 (gchar *, 2);
+ item->slave_devices[0] = g_strdup (g_udev_device_get_device_file (device));
if (mount_paths != NULL)
{
@@ -612,8 +613,9 @@ _stc_item_update_state_filesystem (StcItem *item)
if (_strv_has_str (mount_paths, desired_mount_path))
{
ret = STC_ITEM_STATE_STARTED;
+ item->resulting_mount_path = g_strdup (desired_mount_path);
}
- item->mount_paths = mount_paths; /* adopt */
+ g_strfreev (mount_paths);
}
g_object_unref (device);
@@ -741,8 +743,8 @@ _stc_item_update_state_luks (StcItem *item)
g_strfreev (item->slave_devices);
item->slave_devices = NULL;
- g_free (item->device);
- item->device = NULL;
+ g_free (item->resulting_device);
+ item->resulting_device = NULL;
device_with_crypto = _stc_item_luks_get_devices (item, &unlocked_device);
@@ -756,7 +758,7 @@ _stc_item_update_state_luks (StcItem *item)
if (unlocked_device != NULL)
{
- item->device = g_strdup (g_udev_device_get_device_file (unlocked_device));
+ item->resulting_device = g_strdup (g_udev_device_get_device_file (unlocked_device));
g_object_unref (unlocked_device);
ret = STC_ITEM_STATE_STARTED;
}
@@ -780,8 +782,8 @@ _stc_item_update_state_raid (StcItem *item)
g_strfreev (item->slave_devices);
item->slave_devices = NULL;
- g_free (item->device);
- item->device = NULL;
+ g_free (item->resulting_device);
+ item->resulting_device = NULL;
num_components = 0;
num_devices = 0;
@@ -849,7 +851,7 @@ _stc_item_update_state_raid (StcItem *item)
if (array_device != NULL)
{
ret = STC_ITEM_STATE_STARTED;
- item->device = g_strdup (g_udev_device_get_device_file (array_device));
+ item->resulting_device = g_strdup (g_udev_device_get_device_file (array_device));
}
g_list_foreach (component_devices, (GFunc) g_object_unref, NULL);
@@ -1012,17 +1014,17 @@ stc_item_get_slave_devices (StcItem *item)
}
const gchar *
-stc_item_get_device (StcItem *item)
+stc_item_get_resulting_device (StcItem *item)
{
g_return_val_if_fail (STC_IS_ITEM (item), NULL);
- return item->device;
+ return item->resulting_device;
}
-const gchar *const *
-stc_item_get_mount_paths (StcItem *item)
+const gchar *
+stc_item_get_resulting_mount_path (StcItem *item)
{
g_return_val_if_fail (STC_IS_ITEM (item), NULL);
- return (const gchar *const *) item->mount_paths;
+ return item->resulting_mount_path;
}
/* ---------------------------------------------------------------------------------------------------- */
@@ -1673,6 +1675,9 @@ _stc_item_start_filesystem (StcItem *item,
goto out;
}
g_free (command_line);
+
+ /* Invalidate the mount monitor to ensure it is returning the newly mounted device */
+ _stc_mount_monitor_invalidate (_stc_monitor_get_mount_monitor (item->monitor));
}
else
{
@@ -2030,6 +2035,16 @@ stc_item_start_sync (StcItem *item,
break;
}
+ if (ret)
+ {
+ if (_stc_item_update_state (item))
+ {
+ g_signal_emit_by_name (item->monitor, "item-changed", 0, item);
+ g_signal_emit (item, signals[CHANGED_SIGNAL], 0);
+ }
+ stc_operation_started (operation, item);
+ }
+
out:
return ret;
}
@@ -2260,6 +2275,13 @@ stc_item_stop_sync (StcItem *item,
break;
}
+ if (_stc_item_update_state (item))
+ {
+ g_signal_emit_by_name (item->monitor, "item-changed", 0, item);
+ g_signal_emit (item, signals[CHANGED_SIGNAL], 0);
+ }
+ stc_operation_stopped (operation, item);
+
if (!ret)
goto out;
diff --git a/stc/stcitem.h b/stc/stcitem.h
index 0ca3b11..c88439a 100644
--- a/stc/stcitem.h
+++ b/stc/stcitem.h
@@ -37,28 +37,28 @@ G_BEGIN_DECLS
#define STC_IS_ITEM(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), STC_TYPE_ITEM))
GType stc_item_get_type (void) G_GNUC_CONST;
-StcItemType stc_item_get_item_type (StcItem *item);
-const gchar *stc_item_get_id (StcItem *item);
-const gchar *stc_item_get_comment (StcItem *item);
-const gchar *stc_item_get_target (StcItem *item);
-const gchar* const *stc_item_get_option_keys (StcItem *item);
-const gchar *stc_item_get_option (StcItem *item,
- const gchar *key);
-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* const *stc_item_get_mount_paths (StcItem *item);
+StcItemType stc_item_get_item_type (StcItem *item);
+const gchar *stc_item_get_id (StcItem *item);
+const gchar *stc_item_get_comment (StcItem *item);
+const gchar *stc_item_get_target (StcItem *item);
+const gchar* const *stc_item_get_option_keys (StcItem *item);
+const gchar *stc_item_get_option (StcItem *item,
+ const gchar *key);
+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_resulting_device (StcItem *item);
+const gchar *stc_item_get_resulting_mount_path (StcItem *item);
-gboolean stc_item_start_sync (StcItem *item,
- StcOperation *operation,
- GCancellable *cancellable,
- GError **error);
+gboolean stc_item_start_sync (StcItem *item,
+ StcOperation *operation,
+ GCancellable *cancellable,
+ GError **error);
-gboolean stc_item_stop_sync (StcItem *item,
- StcOperation *operation,
- GCancellable *cancellable,
- GError **error);
+gboolean stc_item_stop_sync (StcItem *item,
+ StcOperation *operation,
+ GCancellable *cancellable,
+ GError **error);
G_END_DECLS
diff --git a/stc/stcmountmonitor.c b/stc/stcmountmonitor.c
index 22f2bce..615962b 100644
--- a/stc/stcmountmonitor.c
+++ b/stc/stcmountmonitor.c
@@ -81,7 +81,7 @@ static guint signals[LAST_SIGNAL] = { 0 };
G_DEFINE_TYPE (_StcMountMonitor, _stc_mount_monitor, G_TYPE_OBJECT)
static void _stc_mount_monitor_ensure (_StcMountMonitor *monitor);
-static void _stc_mount_monitor_invalidate (_StcMountMonitor *monitor);
+//static void _stc_mount_monitor_invalidate (_StcMountMonitor *monitor);
static void _stc_mount_monitor_constructed (GObject *object);
static void
@@ -297,7 +297,7 @@ _stc_mount_monitor_new (void)
return _STC_MOUNT_MONITOR (g_object_new (_STC_TYPE_MOUNT_MONITOR, NULL));
}
-static void
+void
_stc_mount_monitor_invalidate (_StcMountMonitor *monitor)
{
monitor->have_data = FALSE;
diff --git a/stc/stcmountmonitor.h b/stc/stcmountmonitor.h
index 2b6905c..a2bb02d 100644
--- a/stc/stcmountmonitor.h
+++ b/stc/stcmountmonitor.h
@@ -40,6 +40,7 @@ GType _stc_mount_monitor_get_type (void) G_GNUC_CONST;
_StcMountMonitor *_stc_mount_monitor_new (void);
GList *_stc_mount_monitor_get_mounts_for_dev (_StcMountMonitor *monitor,
dev_t dev);
+void _stc_mount_monitor_invalidate (_StcMountMonitor *monitor);
G_END_DECLS
diff --git a/stc/stcoperation.c b/stc/stcoperation.c
index 7ef12e3..e6f8eee 100644
--- a/stc/stcoperation.c
+++ b/stc/stcoperation.c
@@ -71,12 +71,18 @@ struct _StcOperationClass
StcItem *item);
gboolean (*may_start_degraded) (StcOperation *operation,
StcItem *item);
+ void (*started) (StcOperation *operation,
+ StcItem *item);
+ void (*stopped) (StcOperation *operation,
+ StcItem *item);
};
enum
{
REQUEST_PASSPHRASE_SIGNAL,
MAY_START_DEGRADED_SIGNAL,
+ STARTED_SIGNAL,
+ STOPPED_SIGNAL,
LAST_SIGNAL
};
@@ -161,6 +167,42 @@ stc_operation_class_init (StcOperationClass *klass)
G_TYPE_BOOLEAN,
1,
STC_TYPE_ITEM);
+
+ /**
+ * StcOperation::started:
+ * @operation: The #StcOperation emitting the signal.
+ * @item: The item that was just started.
+ *
+ * Emitted when @item has been started.
+ */
+ signals[STARTED_SIGNAL] = g_signal_new ("started",
+ G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (StcOperationClass, started),
+ NULL,
+ NULL,
+ g_cclosure_marshal_VOID__OBJECT,
+ G_TYPE_NONE,
+ 1,
+ STC_TYPE_ITEM);
+
+ /**
+ * StcOperation::stopped:
+ * @operation: The #StcOperation emitting the signal.
+ * @item: The item that was just stopped.
+ *
+ * Emitted when @item has been stopped.
+ */
+ signals[STOPPED_SIGNAL] = g_signal_new ("stopped",
+ G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (StcOperationClass, stopped),
+ NULL,
+ NULL,
+ g_cclosure_marshal_VOID__OBJECT,
+ G_TYPE_NONE,
+ 1,
+ STC_TYPE_ITEM);
}
/**
@@ -225,4 +267,34 @@ stc_operation_may_start_degraded (StcOperation *operation,
return ret;
}
+/**
+ * stc_operation_started:
+ * @operation: A #StcOperation.
+ * @item: A #StcItem.
+ *
+ * Emits the #StcOperation::started signal on @operation.
+ */
+void
+stc_operation_started (StcOperation *operation,
+ StcItem *item)
+{
+ g_return_if_fail (STC_IS_OPERATION (operation));
+ g_return_if_fail (STC_IS_ITEM (item));
+ g_signal_emit (operation, signals[STARTED_SIGNAL], 0, item);
+}
+/**
+ * stc_operation_stopped:
+ * @operation: A #StcOperation.
+ * @item: A #StcItem.
+ *
+ * Emits the #StcOperation::stopped signal on @operation.
+ */
+void
+stc_operation_stopped (StcOperation *operation,
+ StcItem *item)
+{
+ g_return_if_fail (STC_IS_OPERATION (operation));
+ g_return_if_fail (STC_IS_ITEM (item));
+ g_signal_emit (operation, signals[STOPPED_SIGNAL], 0, item);
+}
diff --git a/stc/stcoperation.h b/stc/stcoperation.h
index 551a253..e3885c3 100644
--- a/stc/stcoperation.h
+++ b/stc/stcoperation.h
@@ -42,6 +42,10 @@ gchar *stc_operation_request_passphrase (StcOperation *operation,
StcItem *item);
gboolean stc_operation_may_start_degraded (StcOperation *operation,
StcItem *item);
+void stc_operation_started (StcOperation *operation,
+ StcItem *item);
+void stc_operation_stopped (StcOperation *operation,
+ StcItem *item);
G_END_DECLS