util: getsize now asks the appropriate device 62/166562/27
authorMichal Bloch <m.bloch@samsung.com>
Thu, 8 Feb 2018 14:58:16 +0000 (15:58 +0100)
committerMichal Bloch <m.bloch@samsung.com>
Wed, 21 Feb 2018 14:34:37 +0000 (15:34 +0100)
Additionally, the GETSIZE request now explicitly uses a 32 bit type
so that the protocol does not leave the width undefined.

Change-Id: I1189f2734c670ee68ca76448b8efc410939df952
Signed-off-by: Michal Bloch <m.bloch@samsung.com>
src/logger/logger.c
src/logutil/fd_info.h
src/logutil/fdi_logger.c
src/logutil/fdi_pipe.c
src/logutil/logutil.c

index 85ecb60..1892943 100755 (executable)
@@ -1356,7 +1356,7 @@ static int service_writer_handle_req_getsize(struct logger *server, struct write
        assert(msg);
        assert(msg->request == DLOG_REQ_GETSIZE);
 
-       unsigned buf_size = wr->buf_ptr->size;
+       uint32_t buf_size = wr->buf_ptr->size;
 
        return send_dlog_reply(wr->fd_entity.fd, DLOG_REQ_GETSIZE, DLOG_REQ_RESULT_OK, &buf_size, sizeof buf_size);
 }
index 5f42288..2863260 100644 (file)
@@ -1,6 +1,7 @@
 #pragma once
 
 #include <stdbool.h>
+#include <stdint.h>
 #include <logconfig.h>
 #include <log_file.h>
 #include <logprint.h>
@@ -41,6 +42,9 @@ struct fd_ops {
 
        /// Clear the buffer
        int (*clear)(struct fd_info *fdi);
+
+       /// Get the size of the buffer
+       int (*getsize)(struct fd_info *fdi, uint32_t *val);
 };
 
 struct fd_info *fdi_create(struct fd_ops *ops, const char *name);
index f8a52fa..d2df4e9 100644 (file)
@@ -27,6 +27,18 @@ static int logger_ioctl(int fd, int ioctl_id)
        return ret;
 }
 
+static int logger_getsize(struct fd_info *fdi, uint32_t *val)
+{
+       assert(fdi);
+
+       int r = logger_ioctl(fdi->fd, LOGGER_GET_LOG_BUF_SIZE);
+       if (r < 0)
+               return r;
+
+       *val = (uint32_t)r;
+       return 0;
+}
+
 /**
  * @brief Get buffer filled size
  * @details Sends a get log len ioctl to given fd
@@ -173,5 +185,6 @@ struct fd_ops ops_logger = {
        .extract_entry = logger_extract_entry,
        .prepare_print = logger_prepare_print,
        .clear = logger_clear,
+       .getsize = logger_getsize,
 };
 
index 371295b..d401fa4 100644 (file)
@@ -14,6 +14,33 @@ struct pipe_priv_data {
        int sock_fd;
 };
 
+static int pipe_getsize(struct fd_info *fdi, uint32_t *val)
+{
+       assert(fdi);
+       struct pipe_priv_data *ppd = (struct pipe_priv_data *)fdi->priv_data;
+       assert(ppd);
+       assert(ppd->sock_fd >= 0);
+
+       int r = send_dlog_request(ppd->sock_fd, DLOG_REQ_GETSIZE, NULL, 0);
+       if (r < 0)
+               return r;
+
+       uint32_t *data;
+       int datalen;
+       r = recv_dlog_reply(ppd->sock_fd, DLOG_REQ_GETSIZE, (void **)&data, &datalen);
+       if (r < 0)
+               goto cleanup;
+       if (!data || datalen != sizeof *data) {
+               r = -EINVAL;
+               goto cleanup;
+       }
+       *val = *data;
+
+cleanup:
+       free(data);
+       return r;
+}
+
 /**
  * @brief Clear request
  * @details Send a CLEAR request to the logger daemon
@@ -161,5 +188,6 @@ struct fd_ops ops_pipe = {
        .extract_entry = generic_extract_entry,
        .prepare_print = pipe_prepare_print,
        .clear = pipe_clear,
+       .getsize = pipe_getsize,
 };
 
index ef006e7..3ad09ff 100755 (executable)
@@ -53,34 +53,6 @@ typedef enum action_e {
 } action_e;
 
 /**
- * @brief Get buffer size
- * @details Print the size of the working buffer
- * @param[in] conf The configuration
- * @param[in] names Buffers to process
- * @param[in] cnt Buffer count
- * @return 0 on success, 1 on failure
- */
-static int do_getsize(struct log_config *conf, int enabled_buffers)
-{
-       for (log_id_t i = 0; i < LOG_ID_MAX; ++i) {
-               if (!bit_test(enabled_buffers, i))
-                       continue;
-
-               char conf_key[MAX_CONF_KEY_LEN];
-               const char *const bufname = log_name_by_id(i);
-               snprintf(conf_key, MAX_CONF_KEY_LEN, "%s_size", bufname);
-               const char *conf_value = log_config_get(conf, conf_key);
-               if (!conf_value) {
-                       printf("Error: could not get size of buffer #%d (%s); it has no config entry\n", i, bufname);
-                       return 1;
-               }
-
-               printf("Buffer #%d (%s) has size %d KB\n", i, bufname, BtoKiB(atoi(conf_value)));
-       }
-       return 0;
-}
-
-/**
  * @brief Process log
  * @details Processes a raw log and, if it's old enough, prints it
  * @param[in] e The entry to process
@@ -457,9 +429,6 @@ int main(int argc, char **argv)
        if (!sort_vector_finalize(&logs))
                goto err_nomem;
 
-       if (action == ACTION_GETSIZE)
-               return do_getsize(&conf, enabled_buffers);
-
        conf_value = log_config_get(&conf, "backend");
        if (!conf_value) {
                printf("Error: backend not defined\n");
@@ -489,10 +458,13 @@ int main(int argc, char **argv)
                case ACTION_PRINT: {
                        r = fdi->ops->prepare_print(fdi, dump, filters, l_file.format);
                        break;
-               } case ACTION_GETSIZE:
-                       // r = fdi->ops->getsize(fdi);
+               } case ACTION_GETSIZE: {
+                       uint32_t size;
+                       r = fdi->ops->getsize(fdi, &size);
+                       if (!r)
+                               printf("%s: %u KiB\n", fdi->name, BtoKiB(size));
                        break;
-               default:
+               default:
                        assert(false);
                }