struct gpfs_fsal_obj_handle *alloc_handle(struct gpfs_file_handle *fh, struct fsal_filesystem *fs, struct attrlist *attributes, const char *link_content, struct fsal_export *exp_hdl) { struct gpfs_fsal_export *myself = container_of(exp_hdl, struct gpfs_fsal_export, export); struct gpfs_fsal_obj_handle *hdl = gsh_calloc(1, sizeof(struct gpfs_fsal_obj_handle) + sizeof(struct gpfs_file_handle)); hdl->handle = (struct gpfs_file_handle *)&hdl[1]; hdl->obj_handle.fs = fs; memcpy(hdl->handle, fh, sizeof(struct gpfs_file_handle)); hdl->obj_handle.type = attributes->type; if (hdl->obj_handle.type == REGULAR_FILE) { hdl->u.file.fd.fd = -1; /* no open on this yet */ hdl->u.file.fd.openflags = FSAL_O_CLOSED; } else if (hdl->obj_handle.type == SYMBOLIC_LINK && link_content != NULL) { size_t len = strlen(link_content) + 1; hdl->u.symlink.link_content = gsh_malloc(len); memcpy(hdl->u.symlink.link_content, link_content, len); hdl->u.symlink.link_size = len; } fsal_obj_handle_init(&hdl->obj_handle, exp_hdl, attributes->type); hdl->obj_handle.fsid = attributes->fsid; hdl->obj_handle.fileid = attributes->fileid; gpfs_handle_ops_init(&hdl->obj_handle.obj_ops); if (myself->pnfs_mds_enabled) handle_ops_pnfs(&hdl->obj_handle.obj_ops); return hdl; }
static struct pt_fsal_obj_handle *alloc_handle(ptfsal_handle_t *fh, struct attrlist *attributes, const char *link_content, ptfsal_handle_t *dir_fh, const char *unopenable_name, struct fsal_export *exp_hdl) { struct pt_fsal_obj_handle *hdl; hdl = gsh_malloc(sizeof(struct pt_fsal_obj_handle) + sizeof(ptfsal_handle_t)); if (hdl == NULL) return NULL; memset(hdl, 0, (sizeof(struct pt_fsal_obj_handle) + sizeof(ptfsal_handle_t))); hdl->handle = (ptfsal_handle_t *) &hdl[1]; memcpy(hdl->handle, fh, sizeof(ptfsal_handle_t)); hdl->obj_handle.type = attributes->type; hdl->obj_handle.fs = &pt_filesystem; if (hdl->obj_handle.type == REGULAR_FILE) { hdl->u.file.fd = -1; /* no open on this yet */ hdl->u.file.openflags = FSAL_O_CLOSED; } else if (hdl->obj_handle.type == SYMBOLIC_LINK && link_content != NULL) { size_t len = strlen(link_content) + 1; hdl->u.symlink.link_content = gsh_malloc(len); if (hdl->u.symlink.link_content == NULL) goto spcerr; memcpy(hdl->u.symlink.link_content, link_content, len); hdl->u.symlink.link_size = len; } else if (pt_unopenable_type(hdl->obj_handle.type) && dir_fh != NULL && unopenable_name != NULL) { hdl->u.unopenable.dir = gsh_malloc(sizeof(ptfsal_handle_t)); if (hdl->u.unopenable.dir == NULL) goto spcerr; memcpy(hdl->u.unopenable.dir, dir_fh, sizeof(ptfsal_handle_t)); hdl->u.unopenable.name = gsh_malloc(strlen(unopenable_name) + 1); if (hdl->u.unopenable.name == NULL) goto spcerr; strcpy(hdl->u.unopenable.name, unopenable_name); } hdl->obj_handle.attributes.mask = exp_hdl->ops->fs_supported_attrs(exp_hdl); memcpy(&hdl->obj_handle.attributes, attributes, sizeof(struct attrlist)); fsal_obj_handle_init(&hdl->obj_handle, exp_hdl, attributes->type); return hdl; spcerr: if (hdl->obj_handle.type == SYMBOLIC_LINK) { if (hdl->u.symlink.link_content != NULL) gsh_free(hdl->u.symlink.link_content); } else if (pt_unopenable_type(hdl->obj_handle.type)) { if (hdl->u.unopenable.name != NULL) gsh_free(hdl->u.unopenable.name); if (hdl->u.unopenable.dir != NULL) gsh_free(hdl->u.unopenable.dir); } gsh_free(hdl); /* elvis has left the building */ return NULL; }
/* alloc_handle * allocate and fill in a handle * this uses malloc/free for the time being. */ static struct lustre_fsal_obj_handle *alloc_handle( struct lustre_file_handle *fh, struct fsal_filesystem *fs, struct stat *stat, const char *link_content, struct lustre_file_handle *dir_fh, const char *sock_name, struct fsal_export *exp_hdl) { struct lustre_fsal_obj_handle *hdl; fsal_status_t st; hdl = gsh_malloc(sizeof(struct lustre_fsal_obj_handle) + sizeof(struct lustre_file_handle)); if (hdl == NULL) return NULL; memset(hdl, 0, (sizeof(struct lustre_fsal_obj_handle) + sizeof(struct lustre_file_handle))); hdl->handle = (struct lustre_file_handle *)&hdl[1]; memcpy(hdl->handle, fh, sizeof(struct lustre_file_handle)); hdl->obj_handle.type = posix2fsal_type(stat->st_mode); hdl->dev = posix2fsal_devt(stat->st_dev); hdl->obj_handle.fs = fs; if (hdl->obj_handle.type == REGULAR_FILE) { hdl->u.file.fd = -1; /* no open on this yet */ hdl->u.file.openflags = FSAL_O_CLOSED; } else if (hdl->obj_handle.type == SYMBOLIC_LINK && link_content != NULL) { size_t len = strlen(link_content) + 1; hdl->u.symlink.link_content = gsh_malloc(len); if (hdl->u.symlink.link_content == NULL) goto spcerr; memcpy(hdl->u.symlink.link_content, link_content, len); hdl->u.symlink.link_size = len; } else if (hdl->obj_handle.type == SOCKET_FILE && dir_fh != NULL && sock_name != NULL) { hdl->u.sock.sock_dir = gsh_malloc(sizeof(struct lustre_file_handle)); if (hdl->u.sock.sock_dir == NULL) goto spcerr; memcpy(hdl->u.sock.sock_dir, dir_fh, sizeof(struct lustre_file_handle)); hdl->u.sock.sock_name = gsh_malloc(strlen(sock_name) + 1); if (hdl->u.sock.sock_name == NULL) goto spcerr; strcpy(hdl->u.sock.sock_name, sock_name); } hdl->obj_handle.attributes.mask = exp_hdl->ops->fs_supported_attrs(exp_hdl); st = posix2fsal_attributes(stat, &hdl->obj_handle.attributes); if (FSAL_IS_ERROR(st)) goto spcerr; fsal_obj_handle_init(&hdl->obj_handle, exp_hdl, posix2fsal_type(stat->st_mode)); return hdl; spcerr: if (hdl->obj_handle.type == SYMBOLIC_LINK) { if (hdl->u.symlink.link_content != NULL) gsh_free(hdl->u.symlink.link_content); } else if (hdl->obj_handle.type == SOCKET_FILE) { if (hdl->u.sock.sock_name != NULL) gsh_free(hdl->u.sock.sock_name); if (hdl->u.sock.sock_dir != NULL) gsh_free(hdl->u.sock.sock_dir); } gsh_free(hdl); /* elvis has left the building */ return NULL; }
static struct vfs_fsal_obj_handle *alloc_handle(int dirfd, vfs_file_handle_t *fh, struct fsal_filesystem *fs, struct stat *stat, vfs_file_handle_t *dir_fh, const char *path, struct fsal_export *exp_hdl) { struct vfs_fsal_export *myself = container_of(exp_hdl, struct vfs_fsal_export, export); struct vfs_fsal_obj_handle *hdl; fsal_status_t st; hdl = gsh_calloc(1, (sizeof(struct vfs_fsal_obj_handle) + sizeof(vfs_file_handle_t))); if (hdl == NULL) return NULL; hdl->handle = (vfs_file_handle_t *) &hdl[1]; memcpy(hdl->handle, fh, sizeof(vfs_file_handle_t)); hdl->obj_handle.type = posix2fsal_type(stat->st_mode); hdl->dev = posix2fsal_devt(stat->st_dev); hdl->up_ops = exp_hdl->up_ops; hdl->obj_handle.fs = fs; if (hdl->obj_handle.type == REGULAR_FILE) { hdl->u.file.fd = -1; /* no open on this yet */ hdl->u.file.openflags = FSAL_O_CLOSED; } else if (hdl->obj_handle.type == SYMBOLIC_LINK) { ssize_t retlink; size_t len = stat->st_size + 1; char *link_content = gsh_malloc(len); if (link_content == NULL) goto spcerr; retlink = vfs_readlink_by_handle(fh, dirfd, path, link_content, len); if (retlink < 0 || retlink == len) goto spcerr; link_content[retlink] = '\0'; hdl->u.symlink.link_content = link_content; hdl->u.symlink.link_size = len; } else if (vfs_unopenable_type(hdl->obj_handle.type)) { /* AF_UNIX sockets, character special, and block special files require craziness */ if (dir_fh == NULL) { int retval; vfs_alloc_handle(dir_fh); retval = vfs_fd_to_handle(dirfd, hdl->obj_handle.fs, fh); if (retval < 0) goto spcerr; } hdl->u.unopenable.dir = gsh_malloc(sizeof(vfs_file_handle_t)); if (hdl->u.unopenable.dir == NULL) goto spcerr; memcpy(hdl->u.unopenable.dir, dir_fh, sizeof(vfs_file_handle_t)); hdl->u.unopenable.name = gsh_strdup(path); if (hdl->u.unopenable.name == NULL) goto spcerr; } hdl->obj_handle.attributes.mask = exp_hdl->exp_ops.fs_supported_attrs(exp_hdl); st = posix2fsal_attributes(stat, &hdl->obj_handle.attributes); if (FSAL_IS_ERROR(st)) goto spcerr; hdl->obj_handle.attributes.fsid = fs->fsid; fsal_obj_handle_init(&hdl->obj_handle, exp_hdl, posix2fsal_type(stat->st_mode)); vfs_handle_ops_init(&hdl->obj_handle.obj_ops); vfs_sub_init_handle_ops(myself, &hdl->obj_handle.obj_ops); return hdl; spcerr: if (hdl->obj_handle.type == SYMBOLIC_LINK) { if (hdl->u.symlink.link_content != NULL) gsh_free(hdl->u.symlink.link_content); } else if (vfs_unopenable_type(hdl->obj_handle.type)) { if (hdl->u.unopenable.name != NULL) gsh_free(hdl->u.unopenable.name); if (hdl->u.unopenable.dir != NULL) gsh_free(hdl->u.unopenable.dir); } gsh_free(hdl); /* elvis has left the building */ return NULL; }