Exemplo n.º 1
0
/* Add a path to the hash when we create a directory
 * with the replace=NEVER option
 */
bool path_list_add(JCR *jcr, uint32_t len, char *fname)
{
   bool ret = true;
   CurDir *item;

   if (!jcr->path_list) {
      path_list_init(jcr);
   }

   /* we store CurDir, fname in the same chunk */
   item = (CurDir *)jcr->path_list->hash_malloc(sizeof(CurDir)+len+1);

   memset(item, 0, sizeof(CurDir));
   memcpy(item->fname, fname, len+1);

   jcr->path_list->insert(item->fname, item);

   Dmsg1(dbglvl, "add fname=<%s>\n", fname);
   return ret;
}
Exemplo n.º 2
0
/*
 * Create a parent directory using the cephfs API.
 *
 * We don't use cephfs_mkdirs as we want to keep track which
 * directories got created by us.
 */
static inline bool cephfs_makedirs(plugin_ctx *p_ctx, const char *directory)
{
   char *bp;
   struct stat st;
   bool retval = false;
   POOL_MEM new_directory(PM_FNAME);

   pm_strcpy(new_directory, directory);

   /*
    * See if the parent exists.
    */
   bp = strrchr(new_directory.c_str(), '/');
   if (bp) {
      /*
       * See if we reached the root.
       */
      if (bp == new_directory.c_str()) {
         /*
          * Create the directory.
          */
         if (ceph_mkdir(p_ctx->cmount, directory, 0750) == 0) {
            if (!p_ctx->path_list) {
               p_ctx->path_list = path_list_init();
            }
            path_list_add(p_ctx->path_list, strlen(directory), directory);
            retval = true;
         }
      } else {
         *bp = '\0';

         if (ceph_lstat(p_ctx->cmount, new_directory.c_str(), &st) != 0) {
            switch (errno) {
            case ENOENT:
               /*
                * Make sure our parent exists.
                */
               retval = cephfs_makedirs(p_ctx, new_directory.c_str());
               if (!retval) {
                  return false;
               }

               /*
                * Create the directory.
                */
               if (ceph_mkdir(p_ctx->cmount, directory, 0750) == 0) {
                  if (!p_ctx->path_list) {
                     p_ctx->path_list = path_list_init();
                  }
                  path_list_add(p_ctx->path_list, strlen(directory), directory);
                  retval = true;
               }
               break;
            default:
               break;
            }
         } else {
            retval = true;
         }
      }
   }

   return retval;
}