]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
smbstatus: add locks to byte-range locked files in json output
authorJule Anger <janger@samba.org>
Thu, 31 Mar 2022 08:31:31 +0000 (10:31 +0200)
committerJule Anger <janger@samba.org>
Mon, 8 Aug 2022 12:56:29 +0000 (12:56 +0000)
At the moment, there is only information about the byte-range locked files.
Adds a list of its locks for each file. An open is represented as
a dictionary. Contains all information (pid, dev_inode, read_write, start
and size) about the lock.

Signed-off-by: Jule Anger <janger@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
source3/utils/status.c
source3/utils/status_json.c
source3/utils/status_json.h
source3/utils/status_json_dummy.c

index 97e4f71cc7d19dbbe25eabaa13fe8f4389e25446..f02e8e14951d638b03fd8a79efb62055535d446e 100644 (file)
@@ -412,6 +412,10 @@ static void print_brl(struct file_id id,
        } else {
                print_brl_json(state,
                               pid,
+                              desc,
+                              lock_flav,
+                              (intmax_t)start,
+                              (intmax_t)size,
                               sharepath,
                               fname);
 
index 30b12c46fed48781ff7b50fdeafb735e0d23f8b7..71783916004e9bd47232504c7148b55604d4d10d 100644 (file)
@@ -965,8 +965,80 @@ failure:
        return -1;
 }
 
+static int add_lock_to_json(struct json_object *parent_json,
+                           struct server_id server_id,
+                           const char *type,
+                           enum brl_flavour flavour,
+                           intmax_t start,
+                           intmax_t size)
+{
+       struct json_object sub_json;
+       struct json_object locks_json;
+       const char *flavour_str;
+       int result = 0;
+
+       TALLOC_CTX *tmp_ctx = talloc_stackframe();
+       if (tmp_ctx == NULL) {
+               return -1;
+       }
+
+       locks_json = json_get_array(parent_json, "locks");
+       if (json_is_invalid(&locks_json)) {
+               goto failure;
+       }
+       sub_json = json_new_object();
+       if (json_is_invalid(&sub_json)) {
+               goto failure;
+       }
+
+       result = add_server_id_to_json(&sub_json, server_id);
+       if (result < 0) {
+               goto failure;
+       }
+       result = json_add_string(&sub_json, "type", type);
+       if (result < 0) {
+               goto failure;
+       }
+       flavour_str = talloc_asprintf(tmp_ctx, "%s%s",
+                                     (flavour == WINDOWS_LOCK)?"Windows":"",
+                                     (flavour == POSIX_LOCK)?"Posix":"");
+       result = json_add_string(&sub_json, "flavour", flavour_str);
+       if (result < 0) {
+               goto failure;
+       }
+       result = json_add_int(&sub_json, "start", start);
+       if (result < 0) {
+               goto failure;
+       }
+       result = json_add_int(&sub_json, "size", size);
+       if (result < 0) {
+               goto failure;
+       }
+
+       result = json_add_object(&locks_json, NULL, &sub_json);
+       if (result < 0) {
+               goto failure;
+       }
+       result = json_update_object(parent_json, "locks", &locks_json);
+       if (result < 0) {
+               goto failure;
+       }
+
+       TALLOC_FREE(tmp_ctx);
+       return 0;
+failure:
+       json_free(&locks_json);
+       json_free(&sub_json);
+       TALLOC_FREE(tmp_ctx);
+       return -1;
+}
+
 int print_brl_json(struct traverse_state *state,
                   const struct server_id server_id,
+                  const char *type,
+                  enum brl_flavour flavour,
+                  intmax_t start,
+                  intmax_t size,
                   const char *sharepath,
                   const char *filename)
 {
@@ -1010,6 +1082,10 @@ int print_brl_json(struct traverse_state *state,
        if (result < 0) {
                goto failure;
        }
+       result = add_lock_to_json(&file_json, server_id, type, flavour, start, size);
+       if (result < 0) {
+               goto failure;
+       }
 
        result = json_add_object(&brl_json, key, &file_json);
        if (result < 0) {
index 04b44678db4cea3e82c864edc9dd470a5fc8e385..61e7b6a0540ae7f96fab79a1076f73b0b214ce8c 100644 (file)
@@ -55,6 +55,10 @@ int print_share_mode_json(struct traverse_state *state,
 
 int print_brl_json(struct traverse_state *state,
                   const struct server_id server_id,
+                  const char *type,
+                  enum brl_flavour flavour,
+                  intmax_t start,
+                  intmax_t size,
                   const char *sharepath,
                   const char *filename);
 
index 9a2ccc3db8267637f3bdc785ab7f541f9de3c3d1..c657e55b44f1f08d03387f5836410e301e3140e6 100644 (file)
@@ -72,6 +72,10 @@ int print_share_mode_json(struct traverse_state *state,
 
 int print_brl_json(struct traverse_state *state,
                   const struct server_id server_id,
+                  const char *type,
+                  enum brl_flavour flavour,
+                  intmax_t start,
+                  intmax_t size,
                   const char *sharepath,
                   const char *filename)
 {