Skip to content

Commit c18ce7b

Browse files
committed
Obtain the total number of OSTs, given a folder
This can be done by calling the Lustre user API. int llapi_get_obd_count(char *dir, int *count, int is_mdt);
1 parent 2229a51 commit c18ce7b

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

configure.ac

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1609,6 +1609,8 @@ AC_CHECK_HEADERS([lustre/lustre_user.h linux/lustre/lustre_user.h],
16091609
if test "x$has_lustre" = xyes ; then
16101610
AC_DEFINE(HAVE_LUSTRE, 1, [Define for LUSTRE])
16111611
LIBS="$LIBS -llustreapi"
1612+
# llapi_get_obd_count() can get the total number of available OSTs
1613+
AC_CHECK_FUNCS([llapi_get_obd_count])
16121614
fi
16131615
AM_CONDITIONAL(HAVE_LUSTRE, [test x$has_lustre = xyes])
16141616

src/drivers/pncio/pncio_lustre_open.c

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,52 @@
6262
printf("\t%-14s = %-25s (0x%lx)\n",#val,PATTERN_STR(val, int_str),val); \
6363
}
6464

65+
#ifdef HAVE_LLAPI_GET_OBD_COUNT
66+
67+
/*----< get_total_avail_osts() >---------------------------------------------*/
68+
static
69+
int get_total_avail_osts(const char *path)
70+
{
71+
char *dir_name=NULL, *path_dup=NULL;
72+
int err, ost_count=0, is_mdt=0;
73+
struct stat sb;
74+
75+
path_dup = NCI_Strdup(path);
76+
77+
err = stat(path_dup, &sb);
78+
if (errno == ENOENT) { /* file does not exist, try folder */
79+
/* get the parent folder name */
80+
dir_name = dirname(path_dup);
81+
err = stat(dir_name, &sb);
82+
}
83+
if (err != 0) {
84+
printf("Warning at %s (%d): path \"%s\" stat() failed (%s)\n",
85+
__func__,__LINE__,path,strerror(errno));
86+
goto err_out;
87+
}
88+
89+
/* llapi_get_obd_count() only works for directories */
90+
if (S_ISDIR(sb.st_mode))
91+
dir_name = (dir_name == NULL) ? path_dup : dir_name;
92+
else
93+
/* get the parent folder name */
94+
dir_name = dirname(path_dup);
95+
96+
err = llapi_get_obd_count(dir_name, &ost_count, is_mdt);
97+
if (err != 0) {
98+
printf("Warning at %d: path \"%s\" llapi_get_obd_count() failed (%s)\n",
99+
__LINE__,dir_name,strerror(errno));
100+
ost_count = 0;
101+
}
102+
103+
err_out:
104+
if (path_dup != NULL) NCI_Free(path_dup);
105+
106+
return ost_count;
107+
}
108+
109+
#else
110+
65111
/*----< get_total_avail_osts() >---------------------------------------------*/
66112
static
67113
int get_total_avail_osts(const char *filename)
@@ -192,6 +238,7 @@ int get_total_avail_osts(const char *filename)
192238

193239
return num_members;
194240
}
241+
#endif
195242

196243
static
197244
int compare(const void *a, const void *b)

0 commit comments

Comments
 (0)