diff --git a/home/nipa/nipa_out/861767/ynl/old-code/nfsd-user.c b/home/nipa/nipa_out/861767/ynl/new-code/nfsd-user.c index 7bd072fed96b..e82b2e1287a6 100644 --- a/home/nipa/nipa_out/861767/ynl/old-code/nfsd-user.c +++ b/home/nipa/nipa_out/861767/ynl/new-code/nfsd-user.c @@ -20,6 +20,8 @@ static const char * const nfsd_op_strmap[] = { [NFSD_CMD_VERSION_GET] = "version-get", [NFSD_CMD_LISTENER_SET] = "listener-set", [NFSD_CMD_LISTENER_GET] = "listener-get", + [NFSD_CMD_POOL_MODE_SET] = "pool-mode-set", + [NFSD_CMD_POOL_MODE_GET] = "pool-mode-get", }; const char *nfsd_op_str(int op) @@ -103,6 +105,16 @@ const struct ynl_policy_nest nfsd_server_sock_nest = { .table = nfsd_server_sock_policy, }; +const struct ynl_policy_attr nfsd_pool_mode_policy[NFSD_A_POOL_MODE_MAX + 1] = { + [NFSD_A_POOL_MODE_MODE] = { .name = "mode", .type = YNL_PT_NUL_STR, }, + [NFSD_A_POOL_MODE_NPOOLS] = { .name = "npools", .type = YNL_PT_U32, }, +}; + +const struct ynl_policy_nest nfsd_pool_mode_nest = { + .max_attr = NFSD_A_POOL_MODE_MAX, + .table = nfsd_pool_mode_policy, +}; + /* Common nested types */ void nfsd_version_free(struct nfsd_version *obj) { @@ -709,6 +721,101 @@ struct nfsd_listener_get_rsp *nfsd_listener_get(struct ynl_sock *ys) return NULL; } +/* ============== NFSD_CMD_POOL_MODE_SET ============== */ +/* NFSD_CMD_POOL_MODE_SET - do */ +void nfsd_pool_mode_set_req_free(struct nfsd_pool_mode_set_req *req) +{ + free(req->mode); + free(req); +} + +int nfsd_pool_mode_set(struct ynl_sock *ys, struct nfsd_pool_mode_set_req *req) +{ + struct ynl_req_state yrs = { .yarg = { .ys = ys, }, }; + struct nlmsghdr *nlh; + int err; + + nlh = ynl_gemsg_start_req(ys, ys->family_id, NFSD_CMD_POOL_MODE_SET, 1); + ys->req_policy = &nfsd_pool_mode_nest; + + if (req->_present.mode_len) + ynl_attr_put_str(nlh, NFSD_A_POOL_MODE_MODE, req->mode); + + err = ynl_exec(ys, nlh, &yrs); + if (err < 0) + return -1; + + return 0; +} + +/* ============== NFSD_CMD_POOL_MODE_GET ============== */ +/* NFSD_CMD_POOL_MODE_GET - do */ +void nfsd_pool_mode_get_rsp_free(struct nfsd_pool_mode_get_rsp *rsp) +{ + free(rsp->mode); + free(rsp); +} + +int nfsd_pool_mode_get_rsp_parse(const struct nlmsghdr *nlh, + struct ynl_parse_arg *yarg) +{ + struct nfsd_pool_mode_get_rsp *dst; + const struct nlattr *attr; + + dst = yarg->data; + + ynl_attr_for_each(attr, nlh, yarg->ys->family->hdr_len) { + unsigned int type = ynl_attr_type(attr); + + if (type == NFSD_A_POOL_MODE_MODE) { + unsigned int len; + + if (ynl_attr_validate(yarg, attr)) + return YNL_PARSE_CB_ERROR; + + len = strnlen(ynl_attr_get_str(attr), ynl_attr_data_len(attr)); + dst->_present.mode_len = len; + dst->mode = malloc(len + 1); + memcpy(dst->mode, ynl_attr_get_str(attr), len); + dst->mode[len] = 0; + } else if (type == NFSD_A_POOL_MODE_NPOOLS) { + if (ynl_attr_validate(yarg, attr)) + return YNL_PARSE_CB_ERROR; + dst->_present.npools = 1; + dst->npools = ynl_attr_get_u32(attr); + } + } + + return YNL_PARSE_CB_OK; +} + +struct nfsd_pool_mode_get_rsp *nfsd_pool_mode_get(struct ynl_sock *ys) +{ + struct ynl_req_state yrs = { .yarg = { .ys = ys, }, }; + struct nfsd_pool_mode_get_rsp *rsp; + struct nlmsghdr *nlh; + int err; + + nlh = ynl_gemsg_start_req(ys, ys->family_id, NFSD_CMD_POOL_MODE_GET, 1); + ys->req_policy = &nfsd_pool_mode_nest; + yrs.yarg.rsp_policy = &nfsd_pool_mode_nest; + + rsp = calloc(1, sizeof(*rsp)); + yrs.yarg.data = rsp; + yrs.cb = nfsd_pool_mode_get_rsp_parse; + yrs.rsp_cmd = NFSD_CMD_POOL_MODE_GET; + + err = ynl_exec(ys, nlh, &yrs); + if (err < 0) + goto err_free; + + return rsp; + +err_free: + nfsd_pool_mode_get_rsp_free(rsp); + return NULL; +} + const struct ynl_family ynl_nfsd_family = { .name = "nfsd", .hdr_len = sizeof(struct genlmsghdr), diff --git a/home/nipa/nipa_out/861767/ynl/old-code/nfsd-user.h b/home/nipa/nipa_out/861767/ynl/new-code/nfsd-user.h index 9beeb6ecd46b..df568b15267d 100644 --- a/home/nipa/nipa_out/861767/ynl/old-code/nfsd-user.h +++ b/home/nipa/nipa_out/861767/ynl/new-code/nfsd-user.h @@ -254,4 +254,56 @@ void nfsd_listener_get_rsp_free(struct nfsd_listener_get_rsp *rsp); */ struct nfsd_listener_get_rsp *nfsd_listener_get(struct ynl_sock *ys); +/* ============== NFSD_CMD_POOL_MODE_SET ============== */ +/* NFSD_CMD_POOL_MODE_SET - do */ +struct nfsd_pool_mode_set_req { + struct { + __u32 mode_len; + } _present; + + char *mode; +}; + +static inline struct nfsd_pool_mode_set_req *nfsd_pool_mode_set_req_alloc(void) +{ + return calloc(1, sizeof(struct nfsd_pool_mode_set_req)); +} +void nfsd_pool_mode_set_req_free(struct nfsd_pool_mode_set_req *req); + +static inline void +nfsd_pool_mode_set_req_set_mode(struct nfsd_pool_mode_set_req *req, + const char *mode) +{ + free(req->mode); + req->_present.mode_len = strlen(mode); + req->mode = malloc(req->_present.mode_len + 1); + memcpy(req->mode, mode, req->_present.mode_len); + req->mode[req->_present.mode_len] = 0; +} + +/* + * set the current server pool-mode + */ +int nfsd_pool_mode_set(struct ynl_sock *ys, struct nfsd_pool_mode_set_req *req); + +/* ============== NFSD_CMD_POOL_MODE_GET ============== */ +/* NFSD_CMD_POOL_MODE_GET - do */ + +struct nfsd_pool_mode_get_rsp { + struct { + __u32 mode_len; + __u32 npools:1; + } _present; + + char *mode; + __u32 npools; +}; + +void nfsd_pool_mode_get_rsp_free(struct nfsd_pool_mode_get_rsp *rsp); + +/* + * get info about server pool-mode + */ +struct nfsd_pool_mode_get_rsp *nfsd_pool_mode_get(struct ynl_sock *ys); + #endif /* _LINUX_NFSD_GEN_H */