]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
smbstatus: add oplock information about open files to json output
authorJule Anger <janger@samba.org>
Wed, 30 Mar 2022 13:40:56 +0000 (15:40 +0200)
committerJule Anger <janger@samba.org>
Mon, 8 Aug 2022 12:56:29 +0000 (12:56 +0000)
Adds a dictionary named "oplock" to a opens dictionary.
Contains a string representation and booleans for each oplock type
(EXCLUSIVE, BATCH, LEVEL_II, LEASE).

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 da9510a38d42203291d09c20e7533a7dbf8f4549..b72f618f64552a4d5e0645f306f4b77176493e0c 100644 (file)
@@ -319,6 +319,7 @@ static int print_share_mode(struct file_id fid,
                                              fid,
                                              pid,
                                              user_str,
+                                             oplock,
                                              filename);
                }
        }
index dbfe9dbb89487603d2940e0e152068e9e17dbf5c..6faebdf116bb9a6ce9973ca68a4f01e9b77fb1a3 100644 (file)
@@ -158,6 +158,14 @@ static const struct mask2txt access_mask[] = {
        {0, NULL}
 };
 
+static const struct mask2txt oplock_mask[] = {
+       {EXCLUSIVE_OPLOCK, "EXCLUSIVE"},
+       {BATCH_OPLOCK, "BATCH"},
+       {LEVEL_II_OPLOCK, "LEVEL_II"},
+       {LEASE_OPLOCK, "LEASE"},
+       {0, NULL}
+};
+
 int add_section_to_json(struct traverse_state *state,
                        const char *key)
 {
@@ -459,10 +467,46 @@ failure:
        return -1;
 }
 
+static int add_oplock_to_json(struct json_object *parent_json,
+                             uint16_t op_type,
+                             const char *op_str)
+{
+       struct json_object oplock_json;
+       int result;
+
+       oplock_json = json_new_object();
+       if (json_is_invalid(&oplock_json)) {
+               goto failure;
+       }
+
+       if (op_type != 0) {
+               result = map_mask_to_json(&oplock_json, op_type, oplock_mask);
+               if (result < 0) {
+                       goto failure;
+               }
+               result = json_add_string(&oplock_json, "text", op_str);
+               if (result < 0) {
+                       goto failure;
+               }
+       }
+
+       result = json_add_object(parent_json, "oplock", &oplock_json);
+       if (result < 0) {
+               goto failure;
+       }
+
+       return 0;
+failure:
+       json_free(&oplock_json);
+       return -1;
+}
+
+
 static int add_open_to_json(struct json_object *parent_json,
                            const struct share_mode_entry *e,
                            bool resolve_uids,
                            const char *pid,
+                           const char *op_str,
                            const char *uid_str)
 {
        struct json_object sub_json;
@@ -485,6 +529,7 @@ static int add_open_to_json(struct json_object *parent_json,
                goto failure;
        }
 
+
        result = json_add_string(&sub_json, "pid", pid);
        if (result < 0) {
                goto failure;
@@ -508,6 +553,10 @@ static int add_open_to_json(struct json_object *parent_json,
        if (result < 0) {
                goto failure;
        }
+       result = add_oplock_to_json(&sub_json, e->op_type, op_str);
+       if (result < 0) {
+               goto failure;
+       }
 
        key = talloc_asprintf(tmp_ctx, "%s/%lu", pid, e->share_file_id);
        result = json_add_object(&opens_json, key, &sub_json);
@@ -569,6 +618,7 @@ int print_share_mode_json(struct traverse_state *state,
                          struct file_id fid,
                          const char *pid,
                          const char *uid_str,
+                         const char *op_str,
                          const char *filename)
 {
        struct json_object locks_json;
@@ -617,6 +667,7 @@ int print_share_mode_json(struct traverse_state *state,
                                  e,
                                  state->resolve_uids,
                                  pid,
+                                 op_str,
                                  uid_str);
        if (result < 0) {
                goto failure;
index 5b803080878e088084977982ee305dac1a53ad30..426c831fe7ea38efa09a39654d3a0f20815aac68 100644 (file)
@@ -50,6 +50,7 @@ int print_share_mode_json(struct traverse_state *state,
                          struct file_id fid,
                          const char *pid,
                          const char *uid_str,
+                         const char *op_str,
                          const char *filename);
 
 #endif
index 668a5a63fbdf8ccf7468c498e921e379068da49e..7f72296477ac8e0798336b257cf66b295696229f 100644 (file)
@@ -64,6 +64,7 @@ int print_share_mode_json(struct traverse_state *state,
                          struct file_id fid,
                          const char *pid,
                          const char *uid_str,
+                         const char *op_str,
                          const char *filename)
 {
        return 0;