📄 sanity.c
字号:
/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*- * vim:expandtab:shiftwidth=8:tabstop=8: * * Lustre Light user test program * * Copyright (c) 2002, 2003 Cluster File Systems, Inc. * * This file is part of Lustre, http://www.lustre.org. * * Lustre is free software; you can redistribute it and/or * modify it under the terms of version 2 of the GNU General Public * License as published by the Free Software Foundation. * * Lustre is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Lustre; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */#define _BSD_SOURCE#define _FILE_OFFSET_BITS 64#include <stdio.h>#include <stdlib.h>#include <unistd.h>#include <getopt.h>#include <string.h>#include <sys/types.h>#include <sys/stat.h>#include <fcntl.h>#include <sys/queue.h>#include <signal.h>#include <errno.h>#include <dirent.h>#include <sys/uio.h>#include <sys/time.h>#include <time.h>#include <sys/ioctl.h>#include "test_common.h"#include <ioctl.h>#include <lustre/liblustreapi.h>#ifndef PAGE_SIZE#define PAGE_SIZE getpagesize()#endif#define _npages (2048)void *buf_alloc;int buf_size;int opt_verbose;struct timeval start;extern char *lustre_path;#define ENTRY(str) \ do { \ char buf[100]; \ int len; \ sprintf(buf, "===== START %s: %s ", __FUNCTION__, (str)); \ len = strlen(buf); \ if (len < 79) { \ memset(buf+len, '=', 100-len); \ buf[79] = '\n'; \ buf[80] = 0; \ } \ printf("%s", buf); \ gettimeofday(&start, NULL); \ } while (0)#define LEAVE() \ do { \ struct timeval stop; \ char buf[100] = { '\0' }; \ int len = sizeof(buf) - 1; \ long usec; \ gettimeofday(&stop, NULL); \ usec = (stop.tv_sec - start.tv_sec) * 1000000 + \ (stop.tv_usec - start.tv_usec); \ len = snprintf(buf, len, \ "===== END TEST %s: successfully (%gs)", \ __FUNCTION__, (double)usec / 1000000); \ if (len < 79) { \ memset(buf+len, '=', sizeof(buf) - len); \ buf[79] = '\n'; \ buf[80] = 0; \ } \ printf("%s", buf); \ return 0; \ } while (0)#define MAX_PATH_LENGTH 4096int t1(char *name){ char path[MAX_PATH_LENGTH] = ""; snprintf(path, MAX_PATH_LENGTH, "%s/test_t1", lustre_path); if (opt_verbose) printf("touch+unlink %s\n", path); t_touch(path); t_unlink(path); LEAVE();}int t2(char *name){ char path[MAX_PATH_LENGTH] = ""; ENTRY("mkdir/rmdir"); snprintf(path, MAX_PATH_LENGTH, "%s/test_t2", lustre_path); t_mkdir(path); t_rmdir(path); LEAVE();}int t3(char *name){ char path[MAX_PATH_LENGTH] = ""; ENTRY("regular stat"); snprintf(path, MAX_PATH_LENGTH, "%s/test_t3", lustre_path); t_touch(path); t_check_stat(path, NULL); t_unlink(path); LEAVE();}int t4(char *name){ char path[MAX_PATH_LENGTH] = ""; ENTRY("dir stat"); snprintf(path, MAX_PATH_LENGTH, "%s/test_t4", lustre_path); t_mkdir(path); t_check_stat(path, NULL); t_rmdir(path); LEAVE();}int t6(char *name){ char path[MAX_PATH_LENGTH] = ""; char path2[MAX_PATH_LENGTH] = ""; ENTRY("symlink"); snprintf(path, MAX_PATH_LENGTH, "%s/test_t6", lustre_path); snprintf(path2, MAX_PATH_LENGTH, "%s/test_t6_link", lustre_path); t_touch(path); t_symlink(path, path2); t_check_stat(path2, NULL); t_unlink(path2); t_unlink(path); LEAVE();}int t6b(char *name){ char path[MAX_PATH_LENGTH] = ""; char path2[MAX_PATH_LENGTH] = ""; char cwd[MAX_PATH_LENGTH] = ""; char *tmp; int fd; ENTRY("symlink + chdir and open"); snprintf(path, MAX_PATH_LENGTH, "%s/test_t6b", lustre_path); snprintf(path2, MAX_PATH_LENGTH, "%s/test_t6b_link", lustre_path); t_mkdir(path); t_symlink(path, path2); t_check_stat(path2, NULL); tmp = getcwd(cwd, MAX_PATH_LENGTH); if (tmp == NULL) { fprintf(stderr, "current path too long to fit in " "MAX_PATH_LENGTH?\n"); LEAVE(); } t_chdir(path2); t_chdir(cwd); t_rmdir(path); t_touch(path); fd = t_open(path2); t_close(fd); t_unlink(path2); t_unlink(path); LEAVE();}int t7(char *name){ char path[MAX_PATH_LENGTH] = ""; int rc; ENTRY("mknod"); snprintf(path, MAX_PATH_LENGTH, "%s/test_t7", lustre_path); if (geteuid() != 0) { rc = mknod(path, S_IFCHR | 0644, (5<<8 | 4)); if (rc != -1 || errno != EPERM) { printf("mknod shouldn't success: rc %d, errno %d\n", rc, errno); } } else { t_mknod(path, S_IFCHR | 0644, 5, 4); t_check_stat(path, NULL); t_unlink(path); } LEAVE();}int t8(char *name){ char path[MAX_PATH_LENGTH] = ""; ENTRY("chmod"); snprintf(path, MAX_PATH_LENGTH, "%s/test_t8", lustre_path); /* Check file. */ t_touch(path); t_chmod_raw(path, 0700); t_check_stat(path, NULL); t_unlink(path); /* Check dir. */ t_mkdir(path); t_chmod_raw(path, 0700); t_check_stat(path, NULL); t_rmdir(path); LEAVE();}int t9(char *name){ char path[MAX_PATH_LENGTH] = ""; char path2[MAX_PATH_LENGTH] = ""; ENTRY("hard link"); snprintf(path, MAX_PATH_LENGTH, "%s/test_t9", lustre_path); snprintf(path2, MAX_PATH_LENGTH, "%s/test_t9_link", lustre_path); t_touch(path); t_link(path, path2); t_check_stat(path, NULL); t_check_stat(path2, NULL); t_unlink(path); t_unlink(path2); LEAVE();}int t10(char *name){ char dir1[MAX_PATH_LENGTH] = ""; char dir2[MAX_PATH_LENGTH] = ""; char path1[MAX_PATH_LENGTH] = ""; char path2[MAX_PATH_LENGTH] = ""; char rename1[MAX_PATH_LENGTH] = ""; char rename2[MAX_PATH_LENGTH] = ""; char rename3[MAX_PATH_LENGTH] = ""; ENTRY("rename"); snprintf(dir1, MAX_PATH_LENGTH, "%s/test_t10_dir1", lustre_path); snprintf(dir2, MAX_PATH_LENGTH, "%s/test_t10_dir2", lustre_path); snprintf(path1, MAX_PATH_LENGTH, "%s/test_t10_reg1", lustre_path); snprintf(path2, MAX_PATH_LENGTH, "%s/test_t10_reg2", lustre_path); snprintf(rename1, MAX_PATH_LENGTH, "%s/test_t10_dir1/rename1", lustre_path); snprintf(rename2, MAX_PATH_LENGTH, "%s/test_t10_dir2/rename2", lustre_path); snprintf(rename3, MAX_PATH_LENGTH, "%s/test_t10_dir2/rename3", lustre_path); t_mkdir(dir1); t_mkdir(dir2); t_touch(path1); t_touch(path2); t_rename(path1, rename1); t_rename(path2, rename2); t_rename(rename1, rename2); t_rename(dir1, rename3); t_unlink(rename2); t_rmdir(rename3); t_rmdir(dir2); LEAVE();}int t11(char *name){ char *base=lustre_path; char path[MAX_PATH_LENGTH], path2[MAX_PATH_LENGTH]; int i, j, level = 5, nreg = 5; ENTRY("deep tree"); safe_strncpy(path, base, MAX_PATH_LENGTH); for (i = 0; i < level; i++) { for (j = 0; j < nreg; j++) { sprintf(path2, "%s/file%d", path, j); t_touch(path2); } strcat(path, "/dir"); t_mkdir(path); } for (i = level; i > 0; i--) { safe_strncpy(path, base, MAX_PATH_LENGTH); for (j = 1; j < i; j++) strcat(path, "/dir"); for (j = 0; j < nreg; j++) { sprintf(path2, "%s/file%d", path, j); t_unlink(path2); } strcat(path, "/dir"); t_rmdir(path); } LEAVE();}int t12(char *name){ char dir[MAX_PATH_LENGTH] = ""; char buf[1024*128]; int fd; ENTRY("empty directory readdir"); snprintf(dir, MAX_PATH_LENGTH, "%s/test_t12_dir", lustre_path); t_mkdir(dir); fd = t_opendir(dir); t_ls(fd, buf, sizeof(buf)); t_close(fd); t_rmdir(dir); LEAVE();}int t13(char *name){ char dir[MAX_PATH_LENGTH] = ""; char path[1024]; char buf[1024]; const int nfiles = 20; char *prefix = "test13_filename_prefix_"; int fd, i; ENTRY("multiple entries directory readdir"); snprintf(dir, MAX_PATH_LENGTH, "%s/test_t13_dir/", lustre_path); t_mkdir(dir); printf("Creating %d files...\n", nfiles); for (i = 0; i < nfiles; i++) { sprintf(path, "%s%s%05d", dir, prefix, i); t_touch(path); } fd = t_opendir(dir); t_ls(fd, buf, sizeof(buf)); t_close(fd); printf("Cleanup...\n"); for (i = 0; i < nfiles; i++) { sprintf(path, "%s%s%05d", dir, prefix, i); t_unlink(path); } t_rmdir(dir); LEAVE();}int t14(char *name){ char dir[MAX_PATH_LENGTH] = ""; char path[1024];
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -