00001 #include "fs_parameters.h"
00002 #include "charm.h"
00003
00004 #if CMK_HAS_LUSTREFS
00005 #include <lustre/lustreapi.h>
00006 #include <lustre/lustre_user.h>
00007 #include <errno.h>
00008 #include <libgen.h>
00009 #include <string.h>
00010
00011 static inline int maxInt(int a, int b) {
00012 return a > b ? a : b;
00013 }
00014
00015 static void* alloc_lum() {
00016 int v1, v3;
00017 v1 = sizeof(struct lov_user_md_v1) +
00018 LOV_MAX_STRIPE_COUNT * sizeof(struct lov_user_ost_data_v1);
00019 v3 = sizeof(struct lov_user_md_v3) +
00020 LOV_MAX_STRIPE_COUNT * sizeof(struct lov_user_ost_data_v1);
00021
00022 return malloc(maxInt(v1, v3));
00023 }
00024
00025 size_t CkGetFileStripeSize(const char *filename) {
00026 struct lov_user_md *lump = NULL;
00027 lump = alloc_lum();
00028
00029 if (lump == NULL) {
00030 CkAbort("[CkIO] Cannot allocate memory to extract lustre file stripe size\n");
00031 }
00032
00033 int rc = llapi_file_get_stripe(filename, lump);
00034
00035 if (rc != 0 && errno == ENOENT) {
00036
00037
00038
00039 char* filenameCopy = strdup(filename);
00040 char* directory = dirname(filenameCopy);
00041 rc = llapi_file_get_stripe(directory, lump);
00042 free(filenameCopy);
00043 }
00044
00045 if (rc != 0) {
00046 CkAbort("[CkIO] llapi_file_get_stripe error");
00047 }
00048
00049 return lump->lmm_stripe_size;
00050 }
00051
00052 #else
00053
00054 size_t CkGetFileStripeSize(const char *filename) {
00055 return 4 * 1024 * 1024;
00056 }
00057
00058 #endif