Skip to content

Commit

Permalink
daemon: Replace some ISO struct={ 0 } with C99 init or |memset(&struc…
Browse files Browse the repository at this point in the history
…t,0,sizeof(struct))|

Replace some ISO struct={ 0 } with C99 init or |memset(&struct,0,sizeof(struct))|,
either saving some init work, or letting the profiler see the |memset()|

Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
Signed-off-by: Tigran Mkrtchyan <tigran.mkrtchyan@desy.de>
  • Loading branch information
gisburn authored and kofemann committed Nov 7, 2024
1 parent 67fd156 commit 32c4e46
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 51 deletions.
39 changes: 22 additions & 17 deletions daemon/nfs41_ops.c
Original file line number Diff line number Diff line change
Expand Up @@ -764,13 +764,13 @@ int nfs41_write(
nfs41_putfh_res putfh_res;
nfs41_write_args write_args;
nfs41_write_res write_res;
nfs41_getattr_args getattr_args;
nfs41_getattr_res getattr_res = {0};
bitmap4 attr_request;
nfs41_file_info info = { 0 }, *pinfo;

nfs41_superblock_getattr_mask(file->fh.superblock, &attr_request);

nfs41_getattr_args getattr_args;
nfs41_getattr_res getattr_res = {0};
bitmap4 attr_request;
nfs41_file_info info, *pinfo;

nfs41_superblock_getattr_mask(file->fh.superblock, &attr_request);

compound_init(&compound, argops, resops,
stateid->stateid.seqid == 0 ? "ds write" : "write");

Expand All @@ -786,14 +786,19 @@ int nfs41_write(
write_args.offset = offset;
write_args.stable = stable;
write_args.data_len = data_len;
write_args.data = data;
write_res.resok4.verf = verf;

if (cinfo) pinfo = cinfo;
else pinfo = &info;

if (stable != UNSTABLE4) {
/* if the write is stable, we can't rely on COMMIT to update
write_args.data = data;
write_res.resok4.verf = verf;

if (cinfo) {
pinfo = cinfo;
}
else {
(void)memset(&info, 0, sizeof(info));
pinfo = &info;
}

if (stable != UNSTABLE4) {
/* if the write is stable, we can't rely on COMMIT to update
* the attribute cache, so we do the GETATTR here */
compound_add_op(&compound, OP_GETATTR, &getattr_args, &getattr_res);
getattr_args.attr_request = &attr_request;
Expand Down Expand Up @@ -1839,10 +1844,10 @@ enum nfsstat4 nfs41_fs_locations(
nfs41_lookup_res lookup_res;
nfs41_getattr_args getattr_args;
nfs41_getattr_res getattr_res NDSH(= { 0 });
bitmap4 attr_request = { 1, { FATTR4_WORD0_FS_LOCATIONS } };
bitmap4 attr_request = { .count=1, .arr[0]=FATTR4_WORD0_FS_LOCATIONS };
nfs41_file_info info;

compound_init(&compound, argops, resops, "fs_locations");
compound_init(&compound, argops, resops, "fs_locations");

compound_add_op(&compound, OP_SEQUENCE, &sequence_args, &sequence_res);
nfs41_session_sequence(&sequence_args, session, 0);
Expand Down
32 changes: 18 additions & 14 deletions daemon/readwrite.c
Original file line number Diff line number Diff line change
Expand Up @@ -183,13 +183,15 @@ static int write_to_mds(
unsigned char *p;
const uint32_t maxwritesize = max_write_size(session, &file->fh);
uint32_t to_send, reloffset, len;
int status = 0;
/* on write verifier mismatch, retry N times before failing */
uint32_t retries = MAX_WRITE_RETRIES;
nfs41_file_info info = { 0 };

retry_write:
p = args->buffer;
int status = 0;
/* on write verifier mismatch, retry N times before failing */
uint32_t retries = MAX_WRITE_RETRIES;
nfs41_file_info info;

(void)memset(&info, 0, sizeof(info));

retry_write:
p = args->buffer;
to_send = args->len;
reloffset = 0;
len = 0;
Expand Down Expand Up @@ -258,13 +260,15 @@ static int write_to_pnfs(
IN nfs41_upcall *upcall,
IN stateid_arg *stateid)
{
readwrite_upcall_args *args = &upcall->args.rw;
pnfs_layout_state *layout;
int status = NO_ERROR;
nfs41_file_info info = { 0 };

if (pnfs_layout_state_open(upcall->state_ref, &layout)) {
status = ERROR_NOT_SUPPORTED;
readwrite_upcall_args *args = &upcall->args.rw;
pnfs_layout_state *layout;
int status = NO_ERROR;
nfs41_file_info info;

(void)memset(&info, 0, sizeof(info));

if (pnfs_layout_state_open(upcall->state_ref, &layout)) {
status = ERROR_NOT_SUPPORTED;
goto out;
}

Expand Down
33 changes: 20 additions & 13 deletions daemon/setattr.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,13 @@ static int handle_nfs41_setattr_basicinfo(void *daemon_context, setattr_upcall_a
nfs41_open_state *state = args->state;
nfs41_superblock *superblock = state->file.fh.superblock;
stateid_arg stateid;
nfs41_file_info info = { 0 }, old_info = { 0 };
nfs41_file_info info, old_info;
int status = NO_ERROR;
int getattr_status;

(void)memset(&info, 0, sizeof(info));
(void)memset(&old_info, 0, sizeof(old_info));

getattr_status = nfs41_cached_getattr(state->session,
&state->file, &old_info);
if (getattr_status) {
Expand Down Expand Up @@ -370,14 +373,16 @@ static int handle_nfs41_rename(void *daemon_context, setattr_upcall_args *args)

static int handle_nfs41_set_size(void *daemon_context, setattr_upcall_args *args)
{
nfs41_file_info info = { 0 };
nfs41_file_info info;
stateid_arg stateid;
/* note: this is called with either FILE_END_OF_FILE_INFO or
* FILE_ALLOCATION_INFO, both of which contain a single LARGE_INTEGER */
/* note: this is called with either FILE_END_OF_FILE_INFO or
* FILE_ALLOCATION_INFO, both of which contain a single LARGE_INTEGER */
PLARGE_INTEGER size = (PLARGE_INTEGER)args->buf;
nfs41_open_state *state = args->state;
int status;

(void)memset(&info, 0, sizeof(info));

EASSERT_MSG(args->buf_len == sizeof(size->QuadPart),
("args->buf_len=%ld\n", (long)args->buf_len));

Expand Down Expand Up @@ -420,15 +425,17 @@ static int handle_nfs41_link(void *daemon_context, setattr_upcall_args *args)
PFILE_LINK_INFORMATION link = (PFILE_LINK_INFORMATION)args->buf;
nfs41_session *dst_session;
nfs41_abs_path dst_path = { 0 };
nfs41_path_fh dst_dir, dst;
nfs41_component dst_name;
uint32_t depth = 0;
nfs41_file_info info = { 0 };
int status;

dst_path.len = (unsigned short)WideCharToMultiByte(CP_UTF8, 0,
link->FileName, link->FileNameLength/sizeof(WCHAR),
dst_path.path, NFS41_MAX_PATH_LEN, NULL, NULL);
nfs41_path_fh dst_dir, dst;
nfs41_component dst_name;
uint32_t depth = 0;
nfs41_file_info info;
int status;

(void)memset(&info, 0, sizeof(info));

dst_path.len = (unsigned short)WideCharToMultiByte(CP_UTF8, 0,
link->FileName, link->FileNameLength/sizeof(WCHAR),
dst_path.path, NFS41_MAX_PATH_LEN, NULL, NULL);
if (dst_path.len == 0) {
eprintf("WideCharToMultiByte failed to convert destination "
"filename %S.\n", link->FileName);
Expand Down
14 changes: 7 additions & 7 deletions daemon/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -250,13 +250,13 @@ static __inline void nfstime_diff(
}
static __inline void nfstime_abs(
IN const nfstime4 *nt,
OUT nfstime4 *result)
{
if (nt->seconds < 0) {
const nfstime4 zero = { 0, 0 };
nfstime_diff(&zero, nt, result); /* result = 0 - nt */
} else if (result != nt)
memcpy(result, nt, sizeof(nfstime4));
OUT nfstime4 *result)
{
if (nt->seconds < 0) {
const nfstime4 zero = { .seconds=0LL, .nseconds=0UL };
nfstime_diff(&zero, nt, result); /* result = 0 - nt */
} else if (result != nt)
memcpy(result, nt, sizeof(nfstime4));
}


Expand Down

0 comments on commit 32c4e46

Please sign in to comment.