1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-23 17:34:34 +03:00

smbstatus: add a basic byte-range locks dictionary

Adds an empty json dictionary under the key "byte_range_locks"
and adds foreach locked file a dictionary with information
(path and filename) to the byte-range locks dictionary.

Only print to stdout, if json_output is not set.

Signed-off-by: Jule Anger <janger@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
This commit is contained in:
Jule Anger 2022-03-31 10:30:30 +02:00
parent 6b6b586b8d
commit dc3b10cda6
4 changed files with 91 additions and 11 deletions

View File

@ -349,9 +349,12 @@ static void print_brl_stdout(struct traverse_state *state,
static int prepare_brl(struct traverse_state *state)
{
/* only print header line if there are locked files */
state->first = true;
if (!state->json_output) {
/* only print header line if there are locked files */
state->first = true;
} else {
add_section_to_json(state, "byte_range_locks");
}
return 0;
}
@ -397,14 +400,21 @@ static void print_brl(struct file_id id,
}
}
print_brl_stdout(state,
server_id_str_buf(pid, &tmp),
file_id_str_buf(id, &ftmp),
desc,
(intmax_t)start,
(intmax_t)size,
sharepath,
fname);
if (!state->json_output) {
print_brl_stdout(state,
server_id_str_buf(pid, &tmp),
file_id_str_buf(id, &ftmp),
desc,
(intmax_t)start,
(intmax_t)size,
sharepath,
fname);
} else {
print_brl_json(state,
sharepath,
fname);
}
TALLOC_FREE(fname);
TALLOC_FREE(share_mode);

View File

@ -964,3 +964,62 @@ failure:
TALLOC_FREE(tmp_ctx);
return -1;
}
int print_brl_json(struct traverse_state *state,
const char *sharepath,
const char *filename)
{
struct json_object file_json;
struct json_object brl_json;
int result = 0;
char *key;
TALLOC_CTX *tmp_ctx = talloc_stackframe();
if (tmp_ctx == NULL) {
return -1;
}
if (sharepath[strlen(sharepath)-1] == '/') {
key = talloc_asprintf(tmp_ctx, "%s%s", sharepath, filename);
} else {
key = talloc_asprintf(tmp_ctx, "%s/%s", sharepath, filename);
}
if (key == NULL) {
goto failure;
}
brl_json = json_get_object(&state->root_json, "byte_range_locks");
if (json_is_invalid(&brl_json)) {
goto failure;
}
file_json = json_get_object(&brl_json, key);
if (json_is_invalid(&file_json)) {
goto failure;
}
result = json_add_string(&file_json, "file_name", filename);
if (result < 0) {
goto failure;
}
result = json_add_string(&file_json, "share_path", sharepath);
if (result < 0) {
goto failure;
}
result = json_add_object(&brl_json, key, &file_json);
if (result < 0) {
goto failure;
}
result = json_update_object(&state->root_json, "byte_range_locks", &brl_json);
if (result < 0) {
goto failure;
}
TALLOC_FREE(tmp_ctx);
return 0;
failure:
json_free(&file_json);
json_free(&brl_json);
TALLOC_FREE(tmp_ctx);
return -1;
}

View File

@ -53,4 +53,8 @@ int print_share_mode_json(struct traverse_state *state,
uint32_t lease_type,
const char *filename);
int print_brl_json(struct traverse_state *state,
const char *sharepath,
const char *filename);
#endif

View File

@ -69,3 +69,10 @@ int print_share_mode_json(struct traverse_state *state,
{
return 0;
}
int print_brl_json(struct traverse_state *state,
const char *sharepath,
const char *filename)
{
return 0;
}