"Fossies" - the Fresh Open Source Software Archive

Member "glusterfs-8.2/extras/geo-rep/gsync-sync-gfid.c" (16 Sep 2020, 2552 Bytes) of package /linux/misc/glusterfs-8.2.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. For more information about "gsync-sync-gfid.c" see the Fossies "Dox" file reference documentation.

    1 
    2 #include <stdio.h>
    3 #include <errno.h>
    4 #include <string.h>
    5 #include <limits.h>
    6 #include <sys/types.h>
    7 #include <libgen.h>
    8 #include <ctype.h>
    9 #include <stdlib.h>
   10 #include <glusterfs/glusterfs.h>
   11 #include <glusterfs/syscall.h>
   12 
   13 #ifndef UUID_CANONICAL_FORM_LEN
   14 #define UUID_CANONICAL_FORM_LEN 36
   15 #endif
   16 
   17 #ifndef GF_FUSE_AUX_GFID_HEAL
   18 #define GF_FUSE_AUX_GFID_HEAL "glusterfs.gfid.heal"
   19 #endif
   20 
   21 #define GLFS_LINE_MAX (PATH_MAX + (2 * UUID_CANONICAL_FORM_LEN))
   22 
   23 int
   24 main(int argc, char *argv[])
   25 {
   26     char *file = NULL;
   27     char *tmp = NULL;
   28     char *tmp1 = NULL;
   29     char *parent_dir = NULL;
   30     char *gfid = NULL;
   31     char *bname = NULL;
   32     int ret = -1;
   33     int len = 0;
   34     FILE *fp = NULL;
   35     char line[GLFS_LINE_MAX] = {
   36         0,
   37     };
   38     char *path = NULL;
   39     void *blob = NULL;
   40     void *tmp_blob = NULL;
   41 
   42     if (argc != 2) {
   43         /* each line in the file has the following format
   44          * uuid-in-canonical-form path-relative-to-gluster-mount.
   45          * Both uuid and relative path are from master mount.
   46          */
   47         fprintf(stderr, "usage: %s <file-of-paths-to-be-synced>\n", argv[0]);
   48         goto out;
   49     }
   50 
   51     file = argv[1];
   52 
   53     fp = fopen(file, "r");
   54     if (fp == NULL) {
   55         fprintf(stderr, "cannot open %s for reading (%s)\n", file,
   56                 strerror(errno));
   57         goto out;
   58     }
   59 
   60     while (fgets(line, GLFS_LINE_MAX, fp) != NULL) {
   61         tmp = line;
   62         path = gfid = line;
   63 
   64         path += UUID_CANONICAL_FORM_LEN + 1;
   65 
   66         while (isspace(*path))
   67             path++;
   68 
   69         len = strlen(line);
   70         if ((len < GLFS_LINE_MAX) && (line[len - 1] == '\n'))
   71             line[len - 1] = '\0';
   72 
   73         line[UUID_CANONICAL_FORM_LEN] = '\0';
   74 
   75         tmp = strdup(path);
   76         tmp1 = strdup(path);
   77         parent_dir = dirname(tmp);
   78         bname = basename(tmp1);
   79 
   80         /* gfid + '\0' + bname + '\0' */
   81         len = UUID_CANONICAL_FORM_LEN + 1 + strlen(bname) + 1;
   82 
   83         blob = malloc(len);
   84 
   85         memcpy(blob, gfid, UUID_CANONICAL_FORM_LEN);
   86 
   87         tmp_blob = blob + UUID_CANONICAL_FORM_LEN + 1;
   88 
   89         memcpy(tmp_blob, bname, strlen(bname));
   90 
   91         ret = sys_lsetxattr(parent_dir, GF_FUSE_AUX_GFID_HEAL, blob, len, 0);
   92         if (ret < 0) {
   93             fprintf(stderr, "setxattr on %s/%s failed (%s)\n", parent_dir,
   94                     bname, strerror(errno));
   95         }
   96         memset(line, 0, GLFS_LINE_MAX);
   97 
   98         free(blob);
   99         free(tmp);
  100         free(tmp1);
  101         blob = NULL;
  102     }
  103 
  104     ret = 0;
  105 out:
  106     if (fp)
  107         fclose(fp);
  108     return ret;
  109 }