"Fossies" - the Fresh Open Source Software Archive

Member "glusterfs-6.9/tests/bugs/gfapi/bug-1447266/1460514.c" (23 Apr 2020, 4308 Bytes) of package /linux/misc/glusterfs-6.9.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 #include <fcntl.h>
    2 #include <unistd.h>
    3 #include <time.h>
    4 #include <limits.h>
    5 #include <string.h>
    6 #include <stdio.h>
    7 #include <stdlib.h>
    8 #include <errno.h>
    9 #include <glusterfs/api/glfs.h>
   10 #include <glusterfs/api/glfs-handles.h>
   11 
   12 #define LOG_ERR(func, ret)                                                     \
   13     do {                                                                       \
   14         if (ret != 0) {                                                        \
   15             fprintf(stderr, "%s : returned error %d (%s)\n", func, ret,        \
   16                     strerror(errno));                                          \
   17             goto out;                                                          \
   18         } else {                                                               \
   19             fprintf(stderr, "%s : returned %d\n", func, ret);                  \
   20         }                                                                      \
   21     } while (0)
   22 
   23 int
   24 main(int argc, char *argv[])
   25 {
   26     int ret = 0;
   27     glfs_t *fs = NULL;
   28     struct glfs_object *root = NULL, *dir = NULL, *subdir = NULL;
   29     struct stat sb = {
   30         0,
   31     };
   32     char *dirname = "dir";
   33     char *subdirname = "subdir";
   34     char *logfile = NULL;
   35     char *volname = NULL;
   36     char *hostname = NULL;
   37     unsigned char subdir_handle[GFAPI_HANDLE_LENGTH] = {'\0'};
   38 
   39     if (argc != 4) {
   40         fprintf(stderr, "Invalid argument\n");
   41         exit(1);
   42     }
   43 
   44     hostname = argv[1];
   45     volname = argv[2];
   46     logfile = argv[3];
   47 
   48     fs = glfs_new(volname);
   49     if (!fs) {
   50         fprintf(stderr, "glfs_new: returned NULL\n");
   51         ret = -1;
   52         goto out;
   53     }
   54 
   55     ret = glfs_set_volfile_server(fs, "tcp", hostname, 24007);
   56     LOG_ERR("glfs_set_volfile_server", ret);
   57 
   58     ret = glfs_set_logging(fs, logfile, 7);
   59     LOG_ERR("glfs_set_logging", ret);
   60 
   61     ret = glfs_init(fs);
   62     LOG_ERR("first attempt glfs_init", ret);
   63 
   64     root = glfs_h_lookupat(fs, NULL, "/", &sb, 0);
   65     if (root == NULL) {
   66         fprintf(stderr, "glfs_h_lookupat: error on lookup of / ,%s\n",
   67                 strerror(errno));
   68         goto out;
   69     }
   70     dir = glfs_h_mkdir(fs, root, dirname, 0644, &sb);
   71     if (dir == NULL) {
   72         fprintf(stderr, "glfs_h_mkdir: error on directory creation dir ,%s\n",
   73                 strerror(errno));
   74         goto out;
   75     }
   76     subdir = glfs_h_mkdir(fs, root, subdirname, 0644, &sb);
   77     if (subdir == NULL) {
   78         fprintf(stderr,
   79                 "glfs_h_mkdir: error on directory creation subdir ,%s\n",
   80                 strerror(errno));
   81         goto out;
   82     }
   83     ret = glfs_h_extract_handle(subdir, subdir_handle, GFAPI_HANDLE_LENGTH);
   84     if (ret < 0) {
   85         fprintf(stderr,
   86                 "glfs_h_extract_handle: error extracting handle of %s: %s\n",
   87                 subdirname, strerror(errno));
   88         goto out;
   89     }
   90 
   91     glfs_h_close(subdir);
   92     subdir = NULL;
   93     glfs_h_close(dir);
   94     dir = NULL;
   95 
   96     if (fs) {
   97         ret = glfs_fini(fs);
   98         fprintf(stderr, "glfs_fini(fs) returned %d \n", ret);
   99     }
  100 
  101     fs = NULL;
  102 
  103     fs = glfs_new(volname);
  104     if (!fs) {
  105         fprintf(stderr, "glfs_new: returned NULL\n");
  106         ret = -1;
  107         goto out;
  108     }
  109 
  110     ret = glfs_set_volfile_server(fs, "tcp", hostname, 24007);
  111     LOG_ERR("glfs_set_volfile_server", ret);
  112 
  113     ret = glfs_set_logging(fs, logfile, 7);
  114     LOG_ERR("glfs_set_logging", ret);
  115 
  116     ret = glfs_init(fs);
  117     LOG_ERR("second attempt glfs_init", ret);
  118 
  119     subdir = glfs_h_create_from_handle(fs, subdir_handle, GFAPI_HANDLE_LENGTH,
  120                                        &sb);
  121     if (subdir == NULL) {
  122         fprintf(
  123             stderr,
  124             "glfs_h_create_from_handle: error on create of %s: from (%p),%s\n",
  125             subdirname, subdir_handle, strerror(errno));
  126         goto out;
  127     }
  128     dir = glfs_h_lookupat(fs, subdir, "..", &sb, 0);
  129     if (dir == NULL) {
  130         fprintf(stderr,
  131                 "glfs_h_lookupat: error on directory lookup dir using .. ,%s\n",
  132                 strerror(errno));
  133         goto out;
  134     }
  135 
  136 out:
  137     if (subdir)
  138         glfs_h_close(subdir);
  139     if (dir)
  140         glfs_h_close(dir);
  141 
  142     if (fs) {
  143         ret = glfs_fini(fs);
  144         fprintf(stderr, "glfs_fini(fs) returned %d \n", ret);
  145     }
  146 
  147     if (ret)
  148         exit(1);
  149     exit(0);
  150 }