--- /dev/null
+.so man3/llapi_search_tgt.3
--- /dev/null
+.so man3/llapi_search_tgt.3
--- /dev/null
+.TH llapi_search_tgt 3 "2019 Jun 06" "Lustre User API"
+.SH NAME
+llapi_search_tgt \- verify OST or MDT is in specified pool
+.SH SYNOPSIS
+.nf
+.B #include <lustre/lustreapi.h>
+.PP
+.IB int " llapi_search_tgt(" "const char *fsname" ", " "const char *pool_name" ,
+.BI "const char *tgt_name" ", " "bool is_mdt" );
+.PP
+.IB int " llapi_search_mdt(" "const char *fsname" ", " "const char *pool_name" ,
+.BI "const char *tgt_name" );
+.PP
+.IB int " llapi_search_ost(" "const char *fsname" ", " "const char *pool_name" ,
+.BI "const char *tgt_name" );
+.SH DESCRIPTION
+.PP
+.B llapi_search_tgt()
+verifies that the specified
+.I tgt_name
+is a valid MDT or OST (depending on whether
+.I is_mdt
+is
+.B true
+or
+.BR false ,
+respectively) in the filesystem named
+.I fsname
+and (if specified) in the pool named
+.I pool_name
+of that filesystem. At least
+.I fsname
+must be non-NULL, but
+.I pool_name
+may be
+.B NULL
+if just checking for the existence of the target, and
+.I tgt_name
+may be
+.BR NULL ,
+if only checking the existence of
+.IR pool_name .
+.PP
+The
+.B llapi_search_mdt()
+and
+.B llapi_search_ost()
+functions are simple convenience/compatibility wrappers of
+.B llapi_search_tgt()
+that set
+.I is_mdt
+appropriately for the target type.
+.SH RETURN VALUES
+.LP
+.B llapi_search_tgt()
+returns 1 if
+.I tgt_name
+(or
+.I pool_name
+if
+.I tgt_name
+is
+.BR NULL )
+is found in the specified pool
+(or
+.I filesystem
+if
+.I pool_name
+is
+.BR NULL ).
+It returns 0 if
+.I tgt_name
+.RI ( pool_name )
+if it is not found in the specified pool
+.RI ( filesystem ).
+A negative errno is returned if an error occurred, in which case errno
+is also set appropriately.
+.SH ERRORS
+.TP 15
+.SM EINVAL
+.I fsname
+is NULL or zero-length, or both
+.I pool_name
+and
+.I tgt_name
+are
+.BR NULL .
+.TP 15
+.SM ENOENT
+.I pool_name
+is specified but is not part of
+.IR fsname .
+.SH "SEE ALSO"
+.BR llapi_pool_name_verify (3),
+.BR lustreapi (7),
+.BR lustre (7)
.BR llapi_path2fid (3),
.BR llapi_path2parent (3),
.BR llapi_quotactl (3),
+.BR llapi_search_tgt (3),
.BR lustre (7)
.SH AUTHOR
Lustre contributors
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);
-int llapi_search_tgt(char *fsname, char *poolname, char *tgtname, bool is_mdt);
-int llapi_search_ost(char *fsname, char *poolname, char *ostname);
+int llapi_search_tgt(const char *fsname, const char *poolname,
+ const char *tgtname, bool is_mdt);
+int llapi_search_mdt(const char *fsname, const char *poolname,
+ const char *mdtname);
+int llapi_search_ost(const char *fsname, const char *poolname,
+ const char *ostname);
int llapi_get_obd_count(char *mnt, int *count, int is_mdt);
int llapi_parse_size(const char *optarg, unsigned long long *size,
unsigned long long *size_units, int bytes_spec);
return get_param_lmv(path, "uuid", buf, bufsize);
}
-/*
- * if pool is NULL, search tgtname in target_obd
- * if pool is not NULL:
- * if pool not found returns errno < 0
- * if tgtname is NULL, returns 1 if pool is not empty and 0 if pool empty
- * if tgtname is not NULL, returns 1 if OST is in pool and 0 if not
- */
-int llapi_search_tgt(char *fsname, char *poolname, char *tgtname, bool is_mdt)
-{
- char buffer[PATH_MAX];
- size_t len = 0;
- glob_t param;
- FILE *fd;
- int rc;
-
- /* You need one or the other */
- if (poolname == NULL && fsname == NULL)
- return -EINVAL;
-
- if (tgtname != NULL)
- len = strlen(tgtname);
-
- if (poolname == NULL && len == 0)
- return -EINVAL;
-
- /* Search by poolname and fsname if is not NULL */
- if (poolname != NULL) {
- rc = poolpath(¶m, fsname, NULL);
- if (rc == 0) {
- snprintf(buffer, sizeof(buffer), "%s/%s",
- param.gl_pathv[0], poolname);
- }
- } else if (fsname != NULL) {
- rc = get_lustre_param_path(is_mdt ? "lmv" : "lov", fsname,
- FILTER_BY_FS_NAME,
- "target_obd", ¶m);
- if (rc == 0) {
- strncpy(buffer, param.gl_pathv[0],
- sizeof(buffer) - 1);
- }
- } else {
- return -EINVAL;
- }
- cfs_free_param_data(¶m);
- if (rc)
- return rc;
-
- fd = fopen(buffer, "r");
- if (fd == NULL)
- return -errno;
-
- while (fgets(buffer, sizeof(buffer), fd) != NULL) {
- if (poolname == NULL) {
- char *ptr;
- /* Search for an tgtname in the list of targets
- * Line format is IDX: fsname-OST/MDTxxxx_UUID STATUS */
- ptr = strchr(buffer, ' ');
- if ((ptr != NULL) &&
- (strncmp(ptr + 1, tgtname, len) == 0)) {
- fclose(fd);
- return 1;
- }
- } else {
- /* Search for an tgtname in a pool,
- * (or an existing non-empty pool if no tgtname) */
- if ((tgtname == NULL) ||
- (strncmp(buffer, tgtname, len) == 0)) {
- fclose(fd);
- return 1;
- }
- }
- }
- fclose(fd);
- return 0;
-}
-
-int llapi_search_ost(char *fsname, char *poolname, char *ostname)
-{
- return llapi_search_tgt(fsname, poolname, ostname, false);
-}
-
/**
* Open a Lustre file.
*
return rc;
}
#endif /* LUSTRE_VERSION_CODE < OBD_OCD_VERSION(3, 4, 53, 0) */
+
+/*
+ * fsname must be specified
+ * if poolname is NULL, search tgtname in fsname
+ * if poolname is not NULL:
+ * if poolname not found returns errno < 0
+ * if tgtname is NULL, returns 1 if pool is not empty and 0 if pool empty
+ * if tgtname is not NULL, returns 1 if target is in pool and 0 if not
+ */
+int llapi_search_tgt(const char *fsname, const char *poolname,
+ const char *tgtname, bool is_mdt)
+{
+ char buffer[PATH_MAX];
+ size_t len = 0;
+ glob_t param;
+ FILE *fd;
+ int rc;
+
+ if (fsname && fsname[0] == '\0')
+ fsname = NULL;
+ if (!fsname) {
+ rc = -EINVAL;
+ goto out;
+ }
+
+ if (poolname && poolname[0] == '\0')
+ poolname = NULL;
+ if (tgtname) {
+ if (tgtname[0] == '\0')
+ tgtname = NULL;
+ else
+ len = strlen(tgtname);
+ }
+
+ /* You need one or the other to have something in it */
+ if (!poolname && !tgtname) {
+ rc = -EINVAL;
+ goto out;
+ }
+
+ if (poolname) {
+ rc = poolpath(¶m, fsname, NULL);
+ if (!rc) {
+ snprintf(buffer, sizeof(buffer) - 1, "%s/%s",
+ param.gl_pathv[0], poolname);
+ buffer[sizeof(buffer) - 1] = '\0';
+ }
+ } else {
+ rc = get_lustre_param_path(is_mdt ? "lmv" : "lov", fsname,
+ FILTER_BY_FS_NAME,
+ "target_obd", ¶m);
+ if (!rc) {
+ strncpy(buffer, param.gl_pathv[0],
+ sizeof(buffer) - 1);
+ buffer[sizeof(buffer) - 1] = '\0';
+ }
+ }
+ cfs_free_param_data(¶m);
+ if (rc)
+ goto out;
+
+ fd = fopen(buffer, "r");
+ if (!fd) {
+ rc = -errno;
+ goto out;
+ }
+
+ while (fgets(buffer, sizeof(buffer), fd)) {
+ if (!poolname) {
+ char *ptr;
+ /* Search for an tgtname in the list of all targets
+ * Line format is IDX: fsname-OST/MDTxxxx_UUID STATUS */
+ ptr = strchr(buffer, ' ');
+ if (ptr && strncmp(ptr + 1, tgtname, len) == 0) {
+ rc = 1;
+ goto out_close;
+ }
+ } else {
+ /* Search for an tgtname in a pool,
+ * (or an existing non-empty pool if no tgtname) */
+ if (!tgtname || strncmp(buffer, tgtname, len) == 0) {
+ rc = 1;
+ goto out_close;
+ }
+ }
+ }
+out_close:
+ fclose(fd);
+out:
+ if (rc < 0)
+ errno = -rc;
+ return rc;
+}
+
+int llapi_search_mdt(const char *fsname, const char *poolname,
+ const char *mdtname)
+{
+ return llapi_search_tgt(fsname, poolname, mdtname, true);
+}
+
+int llapi_search_ost(const char *fsname, const char *poolname,
+ const char *ostname)
+{
+ return llapi_search_tgt(fsname, poolname, ostname, false);
+}
+