liblustreapi.c
来自「lustre 1.6.5 source code」· C语言 代码 · 共 1,677 行 · 第 1/4 页
C
1,677 行
/* Print everything */ llapi_printf(LLAPI_MSG_NORMAL, "%s", buf); } } param->obds_printed = 1; fclose(fp); if (!param->quiet && param->obduuid && (param->obdindex == OBD_NOT_FOUND)) { llapi_err_noerrno(LLAPI_MSG_ERROR, "error: %s: unknown obduuid: %s", __FUNCTION__, param->obduuid->uuid); //rc = EINVAL; } return (rc);}/* In this case, param->obduuid will be an array of obduuids and * obd index for all these obduuids will be returned in * param->obdindexes */static int setup_obd_indexes(DIR *dir, struct find_param *param){ struct obd_uuid *uuids = NULL; int obdcount = INIT_ALLOC_NUM_OSTS; int ret, obd_valid = 0, obdnum, i; uuids = (struct obd_uuid *)malloc(INIT_ALLOC_NUM_OSTS * sizeof(struct obd_uuid)); if (uuids == NULL) return -ENOMEM;retry_get_uuids: ret = llapi_lov_get_uuids(dirfd(dir), uuids, &obdcount); if (ret) { struct obd_uuid *uuids_temp; if (ret == -EOVERFLOW) { uuids_temp = realloc(uuids, obdcount * sizeof(struct obd_uuid)); if (uuids_temp != NULL) goto retry_get_uuids; else ret = -ENOMEM; } llapi_err(LLAPI_MSG_ERROR, "get ost uuid failed"); return ret; } param->obdindexes = malloc(param->num_obds * sizeof(param->obdindex)); if (param->obdindexes == NULL) return -ENOMEM; for (obdnum = 0; obdnum < param->num_obds; obdnum++) { for (i = 0; i <= obdcount; i++) { if (strcmp((char *)¶m->obduuid[obdnum].uuid, (char *)&uuids[i]) == 0) { param->obdindexes[obdnum] = i; obd_valid++; break; } } if (i == obdcount) param->obdindexes[obdnum] = OBD_NOT_FOUND; } if (obd_valid == 0) param->obdindex = OBD_NOT_FOUND; else param->obdindex = obd_valid; param->got_uuids = 1; return 0;}void lov_dump_user_lmm_v1(struct lov_user_md_v1 *lum, char *path, int is_dir, int obdindex, int quiet, int header, int body){ int i, obdstripe = 0; if (obdindex != OBD_NOT_FOUND) { for (i = 0; !is_dir && i < lum->lmm_stripe_count; i++) { if (obdindex == lum->lmm_objects[i].l_ost_idx) { llapi_printf(LLAPI_MSG_NORMAL, "%s\n", path); obdstripe = 1; break; } } } else if (!quiet) { llapi_printf(LLAPI_MSG_NORMAL, "%s\n", path); obdstripe = 1; } /* if it's a directory */ if (is_dir) { if (obdstripe == 1) { if (lum->lmm_object_gr == LOV_OBJECT_GROUP_DEFAULT) { llapi_printf(LLAPI_MSG_NORMAL, "(Default) "); lum->lmm_object_gr = LOV_OBJECT_GROUP_CLEAR; } llapi_printf(LLAPI_MSG_NORMAL, "stripe_count: %d stripe_size: %u " "stripe_offset: %d\n", lum->lmm_stripe_count == (__u16)-1 ? -1 : lum->lmm_stripe_count, lum->lmm_stripe_size, lum->lmm_stripe_offset == (__u16)-1 ? -1 : lum->lmm_stripe_offset); } return; } if (header && (obdstripe == 1)) { llapi_printf(LLAPI_MSG_NORMAL, "lmm_magic: 0x%08X\n", lum->lmm_magic); llapi_printf(LLAPI_MSG_NORMAL, "lmm_object_gr: "LPX64"\n", lum->lmm_object_gr); llapi_printf(LLAPI_MSG_NORMAL, "lmm_object_id: "LPX64"\n", lum->lmm_object_id); llapi_printf(LLAPI_MSG_NORMAL, "lmm_stripe_count: %u\n", (int)lum->lmm_stripe_count); llapi_printf(LLAPI_MSG_NORMAL, "lmm_stripe_size: %u\n", lum->lmm_stripe_size); llapi_printf(LLAPI_MSG_NORMAL, "lmm_stripe_pattern: %x\n", lum->lmm_pattern); } if (body) { if ((!quiet) && (obdstripe == 1)) llapi_printf(LLAPI_MSG_NORMAL, "\tobdidx\t\t objid\t\tobjid\t\t group\n"); for (i = 0; i < lum->lmm_stripe_count; i++) { int idx = lum->lmm_objects[i].l_ost_idx; long long oid = lum->lmm_objects[i].l_object_id; long long gr = lum->lmm_objects[i].l_object_gr; if ((obdindex == OBD_NOT_FOUND) || (obdindex == idx)) llapi_printf(LLAPI_MSG_NORMAL, "\t%6u\t%14llu\t%#13llx\t%14llu%s\n", idx, oid, oid, gr, obdindex == idx ? " *" : ""); } llapi_printf(LLAPI_MSG_NORMAL, "\n"); }}void lov_dump_user_lmm_join(struct lov_user_md_v1 *lum, char *path, int is_dir, int obdindex, int quiet, int header, int body){ struct lov_user_md_join *lumj = (struct lov_user_md_join *)lum; int i, obdstripe = 0; if (obdindex != OBD_NOT_FOUND) { for (i = 0; i < lumj->lmm_stripe_count; i++) { if (obdindex == lumj->lmm_objects[i].l_ost_idx) { llapi_printf(LLAPI_MSG_NORMAL, "%s\n", path); obdstripe = 1; break; } } } else if (!quiet) { llapi_printf(LLAPI_MSG_NORMAL, "%s\n", path); obdstripe = 1; } if (header && obdstripe == 1) { llapi_printf(LLAPI_MSG_NORMAL, "lmm_magic: 0x%08X\n", lumj->lmm_magic); llapi_printf(LLAPI_MSG_NORMAL, "lmm_object_gr: "LPX64"\n", lumj->lmm_object_gr); llapi_printf(LLAPI_MSG_NORMAL, "lmm_object_id: "LPX64"\n", lumj->lmm_object_id); llapi_printf(LLAPI_MSG_NORMAL, "lmm_stripe_count: %u\n", (int)lumj->lmm_stripe_count); llapi_printf(LLAPI_MSG_NORMAL, "lmm_stripe_size: %u\n", lumj->lmm_stripe_size); llapi_printf(LLAPI_MSG_NORMAL, "lmm_stripe_pattern: %x\n", lumj->lmm_pattern); llapi_printf(LLAPI_MSG_NORMAL, "lmm_extent_count: %x\n", lumj->lmm_extent_count); } if (body) { unsigned long long start = -1, end = 0; if (!quiet && obdstripe == 1) llapi_printf(LLAPI_MSG_NORMAL, "joined\tobdidx\t\t objid\t\tobjid\t\t group" "\t\tstart\t\tend\n"); for (i = 0; i < lumj->lmm_stripe_count; i++) { int idx = lumj->lmm_objects[i].l_ost_idx; long long oid = lumj->lmm_objects[i].l_object_id; long long gr = lumj->lmm_objects[i].l_object_gr; if (obdindex == OBD_NOT_FOUND || obdindex == idx) llapi_printf(LLAPI_MSG_NORMAL, "\t%6u\t%14llu\t%#13llx\t%14llu%s", idx, oid, oid, gr, obdindex == idx ? " *" : ""); if (start != lumj->lmm_objects[i].l_extent_start || end != lumj->lmm_objects[i].l_extent_end) { start = lumj->lmm_objects[i].l_extent_start; llapi_printf(LLAPI_MSG_NORMAL, "\t%14llu", start); end = lumj->lmm_objects[i].l_extent_end; if (end == (unsigned long long)-1) llapi_printf(LLAPI_MSG_NORMAL, "\t\tEOF\n"); else llapi_printf(LLAPI_MSG_NORMAL, "\t\t%llu\n", end); } else { llapi_printf(LLAPI_MSG_NORMAL, "\t\t\t\t\n"); } } llapi_printf(LLAPI_MSG_NORMAL, "\n"); }}void llapi_lov_dump_user_lmm(struct find_param *param, char *path, int is_dir){ switch(*(__u32 *)¶m->lmd->lmd_lmm) { /* lum->lmm_magic */ case LOV_USER_MAGIC_V1: lov_dump_user_lmm_v1(¶m->lmd->lmd_lmm, path, is_dir, param->obdindex, param->quiet, param->verbose, (param->verbose || !param->obduuid)); break; case LOV_USER_MAGIC_JOIN: lov_dump_user_lmm_join(¶m->lmd->lmd_lmm, path, is_dir, param->obdindex, param->quiet, param->verbose, (param->verbose || !param->obduuid)); break; default: llapi_printf(LLAPI_MSG_NORMAL, "unknown lmm_magic: %#x (expecting %#x)\n", *(__u32 *)¶m->lmd->lmd_lmm, LOV_USER_MAGIC_V1); return; }}int llapi_file_get_stripe(const char *path, struct lov_user_md *lum){ const char *fname; char *dname; int fd, rc = 0; fname = strrchr(path, '/'); /* It should be a file (or other non-directory) */ if (fname == NULL) { dname = (char *)malloc(2); if (dname == NULL) return ENOMEM; strcpy(dname, "."); fname = (char *)path; } else { dname = (char *)malloc(fname - path + 1); if (dname == NULL) return ENOMEM; strncpy(dname, path, fname - path); dname[fname - path] = '\0'; fname++; } if ((fd = open(dname, O_RDONLY)) == -1) { rc = errno; free(dname); return rc; } strcpy((char *)lum, fname); if (ioctl(fd, IOC_MDC_GETFILESTRIPE, (void *)lum) == -1) rc = errno; if (close(fd) == -1 && rc == 0) rc = errno; free(dname); return rc;}int llapi_file_lookup(int dirfd, const char *name){ struct obd_ioctl_data data = { 0 }; char rawbuf[8192]; char *buf = rawbuf; int rc; if (dirfd < 0 || name == NULL) return -EINVAL; data.ioc_version = OBD_IOCTL_VERSION; data.ioc_len = sizeof(data); data.ioc_inlbuf1 = (char *)name; data.ioc_inllen1 = strlen(name) + 1; rc = obd_ioctl_pack(&data, &buf, sizeof(rawbuf)); if (rc) { llapi_err(LLAPI_MSG_ERROR, "error: IOC_MDC_LOOKUP pack failed for '%s': rc %d", name, rc); return rc; } return ioctl(dirfd, IOC_MDC_LOOKUP, buf);}int llapi_mds_getfileinfo(char *path, DIR *parent, struct lov_user_mds_data *lmd){ lstat_t *st = &lmd->lmd_st; char *fname = strrchr(path, '/'); int ret = 0; if (parent == NULL) return -EINVAL; fname = (fname == NULL ? path : fname + 1); /* retrieve needed file info */ strncpy((char *)lmd, fname, lov_mds_md_size(MAX_LOV_UUID_COUNT)); ret = ioctl(dirfd(parent), IOC_MDC_GETFILEINFO, (void *)lmd); if (ret) { if (errno == ENOTTY) { /* ioctl is not supported, it is not a lustre fs. * Do the regular lstat(2) instead. */ ret = lstat_f(path, st); if (ret) { llapi_err(LLAPI_MSG_ERROR, "error: %s: lstat failed for %s", __FUNCTION__, path); return ret; } } else if (errno == ENOENT) { llapi_err(LLAPI_MSG_WARN, "warning: %s: %s does not exist", __FUNCTION__, path); return -ENOENT; } else { llapi_err(LLAPI_MSG_ERROR, "error: %s: IOC_MDC_GETFILEINFO failed for %s", __FUNCTION__, path); return ret; } } return 0;}static DIR *opendir_parent(char *path){ DIR *parent; char *fname; char c; fname = strrchr(path, '/'); if (fname == NULL) return opendir("."); c = fname[1]; fname[1] = '\0'; parent = opendir(path); fname[1] = c; return parent;}static int llapi_semantic_traverse(char *path, int size, DIR *parent, semantic_func_t sem_init, semantic_func_t sem_fini, void *data, struct dirent64 *de){ struct dirent64 *dent; int len, ret; DIR *d, *p = NULL; ret = 0; len = strlen(path); d = opendir(path); if (!d && errno != ENOTDIR) { llapi_err(LLAPI_MSG_ERROR, "%s: Failed to open '%s'", __FUNCTION__, path); return -EINVAL; } else if (!d && !parent) { /* ENOTDIR. Open the parent dir. */ p = opendir_parent(path); if (!p) GOTO(out, ret = -EINVAL); } if (sem_init && (ret = sem_init(path, parent ?: p, d, data, de))) goto err; if (!d) GOTO(out, ret = 0); while ((dent = readdir64(d)) != NULL) { ((struct find_param *)data)->have_fileinfo = 0; if (!strcmp(dent->d_name, ".") || !strcmp(dent->d_name, "..")) continue; path[len] = 0; if ((len + dent->d_reclen + 2) > size) { llapi_err(LLAPI_MSG_ERROR, "error: %s: string buffer is too small", __FUNCTION__); break; } strcat(path, "/"); strcat(path, dent->d_name); if (dent->d_type == DT_UNKNOWN) { lstat_t *st = &((struct find_param *)data)->lmd->lmd_st;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?