int solaris_xattr_resolve_path (const char *real_path, char **path) { int ret = -1; char *export_path = NULL; char xattr_path[PATH_MAX] = {0, }; struct stat lstatbuf = {0, }; struct iatt stbuf = {0, }; struct stat statbuf = {0, }; ret = lstat (real_path, &lstatbuf); if (ret != 0 ) return ret; iatt_from_stat (&stbuf, &lstatbuf); if (IA_ISREG(stbuf.ia_type) || IA_ISDIR(stbuf.ia_type)) return -1; ret = make_export_path (real_path, &export_path); if (!ret && export_path) { strcat (export_path, "/"GF_SOLARIS_XATTR_DIR); if (lstat (export_path, &statbuf)) { ret = mkdir (export_path, 0777); if (ret && (errno != EEXIST)) { gf_log (THIS->name, GF_LOG_DEBUG, "mkdir failed," " errno: %d", errno); goto out; } } snprintf(xattr_path, PATH_MAX, "%s%s%lu", export_path, "/", stbuf.ia_ino); ret = lstat (xattr_path, &statbuf); if (ret) { ret = mknod (xattr_path, S_IFREG|O_WRONLY, 0); if (ret && (errno != EEXIST)) { gf_log (THIS->name, GF_LOG_WARNING,"Failed to create " "mapped file %s, error %d", xattr_path, errno); goto out; } } *path = gf_strdup (xattr_path); } out: if (export_path) GF_FREE (export_path); if (*path) return 0; else return -1; }
void dht_layout_dump (dht_layout_t *layout, const char *prefix) { char key[GF_DUMP_MAX_BUF_LEN]; int i = 0; if (!layout) goto out; if (!prefix) goto out; gf_proc_dump_build_key(key, prefix, "cnt"); gf_proc_dump_write(key, "%d", layout->cnt); gf_proc_dump_build_key(key, prefix, "preset"); gf_proc_dump_write(key, "%d", layout->preset); gf_proc_dump_build_key(key, prefix, "gen"); gf_proc_dump_write(key, "%d", layout->gen); if (layout->type != IA_INVAL) { gf_proc_dump_build_key(key, prefix, "inode type"); gf_proc_dump_write(key, "%d", layout->type); } if (!IA_ISDIR (layout->type)) goto out; for (i = 0; i < layout->cnt; i++) { gf_proc_dump_build_key(key, prefix,"list[%d].err", i); gf_proc_dump_write(key, "%d", layout->list[i].err); gf_proc_dump_build_key(key, prefix,"list[%d].start", i); gf_proc_dump_write(key, "%u", layout->list[i].start); gf_proc_dump_build_key(key, prefix,"list[%d].stop", i); gf_proc_dump_write(key, "%u", layout->list[i].stop); if (layout->list[i].xlator) { gf_proc_dump_build_key(key, prefix, "list[%d].xlator.type", i); gf_proc_dump_write(key, "%s", layout->list[i].xlator->type); gf_proc_dump_build_key(key, prefix, "list[%d].xlator.name", i); gf_proc_dump_write(key, "%s", layout->list[i].xlator->name); } } out: return; }
struct glfs_fd * glfs_h_opendir (struct glfs *fs, struct glfs_object *object) { int ret = -1; struct glfs_fd *glfd = NULL; xlator_t *subvol = NULL; inode_t *inode = NULL; loc_t loc = {0, }; /* validate in args */ if ((fs == NULL) || (object == NULL)) { errno = EINVAL; return NULL; } __glfs_entry_fs (fs); /* get the active volume */ subvol = glfs_active_subvol (fs); if (!subvol) { ret = -1; errno = EIO; goto out; } /* get/refresh the in arg objects inode in correlation to the xlator */ inode = glfs_resolve_inode (fs, subvol, object); if (!inode) { errno = ESTALE; goto out; } if (!IA_ISDIR (inode->ia_type)) { ret = -1; errno = ENOTDIR; goto out; } glfd = glfs_fd_new (fs); if (!glfd) goto out; INIT_LIST_HEAD (&glfd->entries); glfd->fd = fd_create (inode, getpid()); if (!glfd->fd) { ret = -1; errno = ENOMEM; goto out; } GLFS_LOC_FILL_INODE (inode, loc, out); /* fop/op */ ret = syncop_opendir (subvol, &loc, glfd->fd); DECODE_SYNCOP_ERR (ret); out: loc_wipe (&loc); if (inode) inode_unref (inode); if (ret && glfd) { glfs_fd_destroy (glfd); glfd = NULL; } else { fd_bind (glfd->fd); glfs_fd_bind (glfd); } glfs_subvol_done (fs, subvol); return glfd; }
int glfs_h_unlink (struct glfs *fs, struct glfs_object *parent, const char *path) { int ret = -1; xlator_t *subvol = NULL; inode_t *inode = NULL; loc_t loc = {0, }; /* validate in args */ if ((fs == NULL) || (parent == NULL) || (path == NULL)) { errno = EINVAL; return -1; } __glfs_entry_fs (fs); /* get the active volume */ subvol = glfs_active_subvol (fs); if ( !subvol ) { ret = -1; errno = EIO; goto out; } /* get/refresh the in arg objects inode in correlation to the xlator */ inode = glfs_resolve_inode (fs, subvol, parent); if (!inode) { errno = ESTALE; goto out; } ret = glfs_resolve_at (fs, subvol, inode, path, &loc, NULL, 0 , 0); if (ret != 0) { goto out; } if (!IA_ISDIR(loc.inode->ia_type)) { ret = syncop_unlink (subvol, &loc); DECODE_SYNCOP_ERR (ret); if (ret != 0) { goto out; } } else { ret = syncop_rmdir (subvol, &loc, 0); DECODE_SYNCOP_ERR (ret); if (ret != 0) { goto out; } } if (ret == 0) ret = glfs_loc_unlink (&loc); out: loc_wipe (&loc); if (inode) inode_unref (inode); glfs_subvol_done (fs, subvol); return ret; }