From bc09757d465d4ee5728157dce4fed0f71841daa7 Mon Sep 17 00:00:00 2001 From: Christoph Lipka Date: Wed, 16 Mar 2016 16:05:53 +0900 Subject: Offline logstorage: On Demand triggering for syncing Logstorage cache and support long options Signed-off-by: Christoph Lipka Change-Id: I2bac5e48a5d210b544a96fe96dc322f28ac472fe --- src/daemon/dlt_daemon_client.c | 29 ++++++++- src/daemon/dlt_daemon_offline_logstorage.c | 95 +++++++++++++++++++++++++++++- src/daemon/dlt_daemon_offline_logstorage.h | 30 ++++++++++ 3 files changed, 151 insertions(+), 3 deletions(-) (limited to 'src/daemon') diff --git a/src/daemon/dlt_daemon_client.c b/src/daemon/dlt_daemon_client.c index c92601e..55413c5 100644 --- a/src/daemon/dlt_daemon_client.c +++ b/src/daemon/dlt_daemon_client.c @@ -2050,10 +2050,37 @@ void dlt_daemon_control_service_logstorage(int sock, DltDaemon *daemon, DltDaemo /* Check if log level of running application needs to be reset */ dlt_daemon_logstorage_reset_application_loglevel(daemon, device_index, daemon_local->flags.offlineLogstorageMaxDevices, verbose); - dlt_logstorage_device_disconnected(&(daemon->storage_handle[device_index])); + dlt_logstorage_device_disconnected(&(daemon->storage_handle[device_index]), ++ DLT_LOGSTORAGE_SYNC_ON_DEVICE_DISCONNECT); dlt_daemon_control_service_response(sock, daemon, daemon_local, DLT_SERVICE_ID_OFFLINE_LOGSTORAGE, DLT_SERVICE_RESPONSE_OK, verbose); } + /* Check for cache synchronization request from log storage ctrl app */ + else if(req->connection_type == DLT_OFFLINE_LOGSTORAGE_SYNC_CACHES) + { + /* trigger logstorage to sync caches */ + if (dlt_daemon_logstorage_sync_cache(daemon, + daemon_local, + req->mount_point, + verbose) == 0) + { + dlt_daemon_control_service_response(sock, + daemon, + daemon_local, + DLT_SERVICE_ID_OFFLINE_LOGSTORAGE, + DLT_SERVICE_RESPONSE_OK, + verbose); + } + else + { + dlt_daemon_control_service_response(sock, + daemon, + daemon_local, + DLT_SERVICE_ID_OFFLINE_LOGSTORAGE, + DLT_SERVICE_RESPONSE_ERROR, + verbose); + } + } else { dlt_daemon_control_service_response(sock, daemon, daemon_local, DLT_SERVICE_ID_OFFLINE_LOGSTORAGE, DLT_SERVICE_RESPONSE_ERROR, verbose); diff --git a/src/daemon/dlt_daemon_offline_logstorage.c b/src/daemon/dlt_daemon_offline_logstorage.c index a6d799e..6e245eb 100644 --- a/src/daemon/dlt_daemon_offline_logstorage.c +++ b/src/daemon/dlt_daemon_offline_logstorage.c @@ -521,7 +521,9 @@ void dlt_daemon_logstorage_write(DltDaemon *daemon, "Disable storage device\n"); /* DLT_OFFLINE_LOGSTORAGE_MAX_WRITE_ERRORS happened, * therefore remove logstorage device */ - dlt_logstorage_device_disconnected(&(daemon->storage_handle[i])); + dlt_logstorage_device_disconnected( + &(daemon->storage_handle[i]), + DLT_LOGSTORAGE_SYNC_ON_DEVICE_DISCONNECT); } } } @@ -593,9 +595,98 @@ int dlt_daemon_logstorage_cleanup(DltDaemon *daemon, if (daemon->storage_handle[i].connection_type == DLT_OFFLINE_LOGSTORAGE_DEVICE_CONNECTED) { - dlt_logstorage_device_disconnected(&daemon->storage_handle[i]); + dlt_logstorage_device_disconnected( + &daemon->storage_handle[i], + DLT_LOGSTORAGE_SYNC_ON_DAEMON_EXIT); } } return 0; } + +int dlt_daemon_logstorage_sync_cache(DltDaemon *daemon, + DltDaemonLocal *daemon_local, + char *mnt_point, + int verbose) +{ + int i = 0; + DltLogStorage *handle = NULL; + + PRINT_FUNCTION_VERBOSE(verbose); + + if (daemon == NULL || mnt_point == NULL) + { + return -1; + } + + if (strlen(mnt_point) > 0) /* mount point is given */ + { + handle = dlt_daemon_logstorage_get_device(daemon, + daemon_local, + mnt_point, + verbose); + if (handle == NULL) + { + return -1; + } + else + { + if (dlt_logstorage_sync_caches(handle) != 0) + { + return -1; + } + } + } + else /* sync caches for all connected logstorage devices */ + { + for(i=0; i < daemon_local->flags.offlineLogstorageMaxDevices; i++) + { + if (daemon->storage_handle[i].connection_type == + DLT_OFFLINE_LOGSTORAGE_DEVICE_CONNECTED) + { + if (dlt_logstorage_sync_caches(&daemon->storage_handle[i]) != 0) + { + return -1; + } + } + } + } + + return 0; +} + +DltLogStorage *dlt_daemon_logstorage_get_device(DltDaemon *daemon, + DltDaemonLocal *daemon_local, + char *mnt_point, + int verbose) +{ + int i = 0; + int len1 = 0; + int len2 = 0; + + PRINT_FUNCTION_VERBOSE(verbose); + + if (daemon == NULL || daemon_local == NULL || mnt_point == NULL) + { + return NULL; + } + + len1 = strlen(mnt_point); + + for(i = 0; i < daemon_local->flags.offlineLogstorageMaxDevices; i++) + { + len2 = strlen(daemon->storage_handle[i].device_mount_point); + + /* Check if the requested device path is already used as log storage + * device. Check for strlen first, to avoid comparison errors when + * final '/' is given or not */ + if (strncmp(daemon->storage_handle[i].device_mount_point, + mnt_point, + len1 > len2 ? len2 : len1) == 0) + { + return &daemon->storage_handle[i]; + } + } + + return NULL; +} diff --git a/src/daemon/dlt_daemon_offline_logstorage.h b/src/daemon/dlt_daemon_offline_logstorage.h index 148abd0..3ab092a 100644 --- a/src/daemon/dlt_daemon_offline_logstorage.h +++ b/src/daemon/dlt_daemon_offline_logstorage.h @@ -150,4 +150,34 @@ int dlt_daemon_logstorage_cleanup(DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose); +/** + * Sync logstorage caches + * + * @param daemon Pointer to Dlt Daemon structure + * @param daemon_local Pointer to Dlt Daemon Local structure + * @param mount_point Logstorage device mount point + * @param verbose If set to true verbose information is printed out + * @return 0 on success, -1 otherwise + */ +int dlt_daemon_logstorage_sync_cache(DltDaemon *daemon, + DltDaemonLocal *daemon_local, + char *mnt_point, + int verbose); + +/** + * dlt_logstorage_get_device + * + * Get a Logstorage device handle for given the mount point. + * + * @param daemon Pointer to Dlt Daemon structure + * @param daemon_local Pointer to Dlt Daemon Local structure + * @param mount_point Logstorage device mount point + * @param verbose If set to true verbose information is printed out + * @return handle to Logstorage device on success, NULL otherwise + */ +DltLogStorage *dlt_daemon_logstorage_get_device(DltDaemon *daemon, + DltDaemonLocal *daemon_local, + char *mnt_point, + int verbose); + #endif /* DLT_DAEMON_OFFLINE_LOGSTORAGE_H */ -- cgit v1.2.1