From 25523e5a35138a0534b01ff561169e501cc30787 Mon Sep 17 00:00:00 2001 From: Timothy Day Date: Sat, 24 Jun 2023 18:48:31 +0000 Subject: [PATCH] LU-8191 liblustre: add missing functions to header A number of functions were missing from lustreapi.h, causing them to be marked incorrectly as functions that could be made static. They have been added to the header so applications can use them. Static analysis shows that a number of functions could be made static. This patch also declares several functions in liblustre static. liblustreapi_nodemap.c and liblustreapi_ioctl.c were missing an internal header, causing some functions to be incorrectly flagged. This patch also adds that header. Initialize a previously uninitialized variable in llapi_fid_to_handle(). Test-Parameters: trivial Signed-off-by: Timothy Day Change-Id: I67b9c59418b62602ffe36eb4284eb1e8d4a3b19b Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/51434 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Andreas Dilger Reviewed-by: Patrick Farrell Reviewed-by: James Simmons Reviewed-by: Oleg Drokin --- lustre/include/lustre/lustreapi.h | 7 ++++- lustre/utils/liblustreapi.c | 62 ++++++++++++++++++------------------- lustre/utils/liblustreapi_fid.c | 2 +- lustre/utils/liblustreapi_ioctl.c | 4 ++- lustre/utils/liblustreapi_json.c | 6 ++-- lustre/utils/liblustreapi_nodemap.c | 1 + lustre/utils/liblustreapi_param.c | 4 +-- 7 files changed, 47 insertions(+), 39 deletions(-) diff --git a/lustre/include/lustre/lustreapi.h b/lustre/include/lustre/lustreapi.h index 67fea05..b19c0bc 100644 --- a/lustre/include/lustre/lustreapi.h +++ b/lustre/include/lustre/lustreapi.h @@ -44,6 +44,7 @@ #include #include #include +#include #if defined(__cplusplus) extern "C" { @@ -458,6 +459,7 @@ int llapi_target_check(int num_types, char **obd_types, char *dir); int llapi_file_get_lov_uuid(const char *path, struct obd_uuid *lov_uuid); int llapi_file_get_lmv_uuid(const char *path, struct obd_uuid *lmv_uuid); int llapi_file_fget_lov_uuid(int fd, struct obd_uuid *lov_uuid); +int llapi_file_fget_lmv_uuid(int fd, struct obd_uuid *lov_uuid); int llapi_lov_get_uuids(int fd, struct obd_uuid *uuidp, int *ost_count); int llapi_lmv_get_uuids(int fd, struct obd_uuid *uuidp, int *mdt_count); int llapi_is_lustre_mnttype(const char *type); @@ -516,6 +518,7 @@ int llapi_get_lum_dir_fd(int dir_fd, __u64 *valid, lstatx_t *statx, struct lov_user_md *lum, size_t lumsize); int llapi_fd2fid(int fd, struct lu_fid *fid); + /* get FID of parent dir + the related name of entry in this parent dir */ int llapi_path2parent(const char *path, unsigned int linkno, struct lu_fid *parent_fid, char *name, size_t name_size); @@ -526,9 +529,9 @@ int llapi_rmfid_at(int fd, struct fid_array *fa); int llapi_root_path_open(const char *device, int *outfd); int llapi_chomp_string(char *buf); -struct file_handle; int llapi_handle_to_fid(struct file_handle **handle, const struct lu_fid *fid); +int llapi_fid_to_handle(struct file_handle **handle, const struct lu_fid *fid); int llapi_open_by_fid_at(int lustre_fd, const struct lu_fid *fid, int open_flags); int llapi_open_by_fid(const char *lustre_dir, const struct lu_fid *fid, @@ -662,6 +665,7 @@ int llapi_json_write_list(struct llapi_json_item_list **item_list, FILE *fp); /* File lease */ int llapi_lease_acquire(int fd, enum ll_lease_mode mode); +int llapi_lease_release_intent(int fd, struct ll_ioc_lease *data); int llapi_lease_release(int fd); int llapi_lease_set(int fd, const struct ll_ioc_lease *data); int llapi_lease_check(int fd); @@ -1282,6 +1286,7 @@ int llapi_mirror_copy(int fd, unsigned int src, unsigned int dst, off_t pos, size_t count); off_t llapi_mirror_data_seek(int fd, unsigned int id, off_t pos, size_t *size); int llapi_mirror_punch(int fd, unsigned int id, off_t start, size_t length); +bool llapi_mirror_is_sparse(int fd, unsigned int id); int llapi_heat_get(int fd, struct lu_heat *heat); int llapi_heat_set(int fd, __u64 flags); diff --git a/lustre/utils/liblustreapi.c b/lustre/utils/liblustreapi.c index d09989c..eca1453 100644 --- a/lustre/utils/liblustreapi.c +++ b/lustre/utils/liblustreapi.c @@ -411,8 +411,8 @@ out: return rc; } -int llapi_dir_stripe_limit_check(int stripe_offset, int stripe_count, - int hash_type) +static int dir_stripe_limit_check(int stripe_offset, int stripe_count, + int hash_type) { int rc; @@ -776,9 +776,9 @@ static int verify_dir_param(const char *name, } /* Check if the stripe pattern is sane. */ - rc = llapi_dir_stripe_limit_check(param->lsp_stripe_offset, - param->lsp_stripe_count, - param->lsp_stripe_pattern); + rc = dir_stripe_limit_check(param->lsp_stripe_offset, + param->lsp_stripe_count, + param->lsp_stripe_pattern); if (rc != 0) return rc; @@ -2825,11 +2825,11 @@ static void lov_dump_user_lmm_header(struct lov_user_md *lum, char *path, llapi_printf(LLAPI_MSG_NORMAL, "\n"); } -void lov_dump_user_lmm_v1v3(struct lov_user_md *lum, char *pool_name, - struct lov_user_ost_data_v1 *objects, - char *path, int obdindex, int depth, - enum llapi_layout_verbose verbose, - enum lov_dump_flags flags) +static void lov_dump_user_lmm_v1v3(struct lov_user_md *lum, char *pool_name, + struct lov_user_ost_data_v1 *objects, + char *path, int obdindex, int depth, + enum llapi_layout_verbose verbose, + enum lov_dump_flags flags) { bool is_dir = flags & LDF_IS_DIR; bool indent = flags & LDF_INDENT; @@ -2917,10 +2917,10 @@ void lov_dump_user_lmm_v1v3(struct lov_user_md *lum, char *pool_name, llapi_printf(LLAPI_MSG_NORMAL, "\n"); } -void lmv_dump_user_lmm(struct lmv_user_md *lum, char *pool_name, - char *path, int obdindex, int depth, - enum llapi_layout_verbose verbose, - enum lov_dump_flags flags) +static void lmv_dump_user_lmm(struct lmv_user_md *lum, char *pool_name, + char *path, int obdindex, int depth, + enum llapi_layout_verbose verbose, + enum lov_dump_flags flags) { struct lmv_user_mds_data *objects = lum->lum_objects; char *prefix = lum->lum_magic == LMV_USER_MAGIC ? "(Default)" : ""; @@ -3645,8 +3645,8 @@ static inline bool has_any_comp_options(struct find_param *param) return verbose & VERBOSE_COMP_OPTS; } -struct lov_user_mds_data *lov_forge_comp_v1(struct lov_user_mds_data *orig, - bool is_dir) +static struct lov_user_mds_data * +lov_forge_comp_v1(struct lov_user_mds_data *orig, bool is_dir) { struct lov_user_md *lum = &orig->lmd_lmm; struct lov_user_mds_data *new; @@ -4592,7 +4592,8 @@ static bool find_check_lmm_info(struct find_param *param) * as part of the escape sequence (0 for an unrecognized * escape sequence) */ -int printf_format_escape(char *seq, char *buffer, size_t size, int *wrote) +static int printf_format_escape(char *seq, char *buffer, size_t size, + int *wrote) { *wrote = 0; /* For now, only handle single char escape sequences: \n, \t, \\ */ @@ -4628,9 +4629,8 @@ int printf_format_escape(char *seq, char *buffer, size_t size, int *wrote) * @return Number of characters from input string processed * as part of the format (0 for an unknown format) */ - -int printf_format_timestamp(char *seq, char *buffer, size_t size, int *wrote, - struct find_param *param) +static int printf_format_timestamp(char *seq, char *buffer, size_t size, + int *wrote, struct find_param *param) { struct statx_timestamp ts = { 0, 0 }; struct tm *tm; @@ -4841,9 +4841,9 @@ format_done: * @return Number of characters from input string processed * as part of the format (0 for an unknown format) */ -int printf_format_lustre(char *seq, char *buffer, size_t size, int *wrote, - struct find_param *param, char *path, __u32 projid, - int d) +static int printf_format_lustre(char *seq, char *buffer, size_t size, + int *wrote, struct find_param *param, + char *path, __u32 projid, int d) { struct lmv_user_md *lum; struct lmv_user_mds_data *objects; @@ -5050,9 +5050,9 @@ format_done: * @return Number of characters from input string processed * as part of the format (0 for an unknown format) */ -int printf_format_directive(char *seq, char *buffer, size_t size, int *wrote, - struct find_param *param, char *path, __u32 projid, - int d) +static int printf_format_directive(char *seq, char *buffer, size_t size, + int *wrote, struct find_param *param, + char *path, __u32 projid, int d) { __u16 mode = param->fp_lmd->lmd_stx.stx_mode; uint64_t blocks = param->fp_lmd->lmd_stx.stx_blocks; @@ -5146,8 +5146,8 @@ int printf_format_directive(char *seq, char *buffer, size_t size, int *wrote, * @param[in] d File descriptor for current directory (or -1 for a * non-directory file) */ -void printf_format_string(struct find_param *param, char *path, - __u32 projid, int d) +static void printf_format_string(struct find_param *param, char *path, + __u32 projid, int d) { char output[FORMATTED_BUF_LEN]; char *fmt_char = param->fp_format_printf_str; @@ -5989,7 +5989,7 @@ int llapi_mv(char *path, struct find_param *param) * @return Number of characters examined in the escape sequence * (regardless of whether the sequence is valid or not). */ -int validate_printf_esc(char *c) +static int validate_printf_esc(char *c) { char *valid_esc = "nt\\"; @@ -6018,7 +6018,7 @@ int validate_printf_esc(char *c) * @return Number of characters examined in the format directive * (regardless of whether the directive is valid or not). */ -int validate_printf_fmt(char *c) +static int validate_printf_fmt(char *c) { char *valid_fmt_single = "abcGkmnpstUwy%"; char *valid_fmt_double = "ACTW"; @@ -6070,7 +6070,7 @@ check_single: * @param[in] param Structure containing info about invocation of lfs find * @return None */ -void validate_printf_str(struct find_param *param) +static void validate_printf_str(struct find_param *param) { char *c = param->fp_format_printf_str; int ret = 0; diff --git a/lustre/utils/liblustreapi_fid.c b/lustre/utils/liblustreapi_fid.c index 827d8ad..b3bf411 100644 --- a/lustre/utils/liblustreapi_fid.c +++ b/lustre/utils/liblustreapi_fid.c @@ -438,7 +438,7 @@ int llapi_fid_to_handle(struct file_handle **_handle, const struct lu_fid *fid) */ int llapi_open_by_fid_at(int lustre_fd, const struct lu_fid *fid, int flags) { - struct file_handle *handle; + struct file_handle *handle = NULL; int fd; int rc; diff --git a/lustre/utils/liblustreapi_ioctl.c b/lustre/utils/liblustreapi_ioctl.c index 183106c..73cab49 100644 --- a/lustre/utils/liblustreapi_ioctl.c +++ b/lustre/utils/liblustreapi_ioctl.c @@ -43,6 +43,8 @@ #include #include +#include "lustreapi_internal.h" + int llapi_ioctl_pack(struct obd_ioctl_data *data, char **pbuf, int max_len) { struct obd_ioctl_data *overlay; @@ -99,7 +101,7 @@ int llapi_ioctl_pack(struct obd_ioctl_data *data, char **pbuf, int max_len) * \param cmd ioctl command * \param buf ioctl data argument, usually obd_ioctl_data */ -int llapi_ioctl_dev(unsigned int dev_id, unsigned int cmd, void *buf) +int llapi_ioctl_dev(int dev_id, unsigned int cmd, void *buf) { unsigned int oldcmd; int rc; diff --git a/lustre/utils/liblustreapi_json.c b/lustre/utils/liblustreapi_json.c index e19f25f..4c730ce 100644 --- a/lustre/utils/liblustreapi_json.c +++ b/lustre/utils/liblustreapi_json.c @@ -54,7 +54,7 @@ * http://json.org/ * http://www.ietf.org/rfc/rfc4627.txt (section 2.5) */ -int llapi_json_escape_string(char **out_string, char *in_string) +static int json_escape_string(char **out_string, char *in_string) { int i; char escape_chars[] = {'\b', '\f', '\n', '\r', '\t', '"', '\\', @@ -147,8 +147,8 @@ int llapi_json_write_list(struct llapi_json_item_list **json_items, FILE *fp) fprintf(fp, "%f", item->lji_real); break; case LLAPI_JSON_STRING: - if (llapi_json_escape_string(&escaped_string, - item->lji_string) < 0) { + if (json_escape_string(&escaped_string, + item->lji_string) < 0) { if (escaped_string != NULL) free(escaped_string); return -errno; diff --git a/lustre/utils/liblustreapi_nodemap.c b/lustre/utils/liblustreapi_nodemap.c index 5e25fff..f66aeae 100644 --- a/lustre/utils/liblustreapi_nodemap.c +++ b/lustre/utils/liblustreapi_nodemap.c @@ -29,6 +29,7 @@ #include #include #include +#include int llapi_nodemap_exists(const char *nodemap) { diff --git a/lustre/utils/liblustreapi_param.c b/lustre/utils/liblustreapi_param.c index a027850..2932e90 100644 --- a/lustre/utils/liblustreapi_param.c +++ b/lustre/utils/liblustreapi_param.c @@ -505,8 +505,8 @@ static int print_out_devices(yaml_parser_t *reply, enum lctl_param_flags flags) return rc; } -int lcfg_param_get_yaml(yaml_parser_t *reply, struct nl_sock *sk, - int version, char *pattern) +static int lcfg_param_get_yaml(yaml_parser_t *reply, struct nl_sock *sk, + int version, char *pattern) { char source[PATH_MAX / 2], group[GENL_NAMSIZ + 1]; char *family = "lustre", *tmp; -- 1.8.3.1