From: Jule Anger Date: Wed, 30 Mar 2022 13:40:56 +0000 (+0200) Subject: smbstatus: add oplock information about open files to json output X-Git-Tag: samba-4.17.0rc1~21 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=595b0198ec3678018a7a4f551c6324ea88e7f601;p=thirdparty%2Fsamba.git smbstatus: add oplock information about open files to json output 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 Reviewed-by: Ralph Boehme --- diff --git a/source3/utils/status.c b/source3/utils/status.c index da9510a38d4..b72f618f645 100644 --- a/source3/utils/status.c +++ b/source3/utils/status.c @@ -319,6 +319,7 @@ static int print_share_mode(struct file_id fid, fid, pid, user_str, + oplock, filename); } } diff --git a/source3/utils/status_json.c b/source3/utils/status_json.c index dbfe9dbb894..6faebdf116b 100644 --- a/source3/utils/status_json.c +++ b/source3/utils/status_json.c @@ -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; diff --git a/source3/utils/status_json.h b/source3/utils/status_json.h index 5b803080878..426c831fe7e 100644 --- a/source3/utils/status_json.h +++ b/source3/utils/status_json.h @@ -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 diff --git a/source3/utils/status_json_dummy.c b/source3/utils/status_json_dummy.c index 668a5a63fbd..7f72296477a 100644 --- a/source3/utils/status_json_dummy.c +++ b/source3/utils/status_json_dummy.c @@ -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;