Beispiel #1
0
static int
_posix_xattr_get_set (dict_t *xattr_req,
                      char *key,
                      data_t *data,
                      void *xattrargs)
{
        posix_xattr_filler_t *filler = xattrargs;
        char     *value      = NULL;
        ssize_t   xattr_size = -1;
        int       ret      = -1;
        char     *databuf  = NULL;
        int       _fd      = -1;
        loc_t    *loc      = NULL;
        ssize_t  req_size  = 0;


        if (posix_xattr_ignorable (key, filler))
                goto out;
        /* should size be put into the data_t ? */
        if (!strcmp (key, GF_CONTENT_KEY)
            && IA_ISREG (filler->stbuf->ia_type)) {

                /* file content request */
                req_size = data_to_uint64 (data);
                if (req_size >= filler->stbuf->ia_size) {
                        _fd = open (filler->real_path, O_RDONLY);
                        if (_fd == -1) {
                                gf_log (filler->this->name, GF_LOG_ERROR,
                                        "Opening file %s failed: %s",
                                        filler->real_path, strerror (errno));
                                goto err;
                        }
Beispiel #2
0
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;
}
Beispiel #3
0
static gf_boolean_t
posix_xattr_ignorable (char *key, posix_xattr_filler_t *filler)
{
        int          i = 0;
        gf_boolean_t ignore = _gf_false;

        GF_ASSERT (key);
        if (!key)
                goto out;
        for (i = 0; posix_ignore_xattrs[i]; i++) {
                if (!strcmp (key, posix_ignore_xattrs[i])) {
                        ignore = _gf_true;
                        goto out;
                }
        }
        if ((!strcmp (key, GF_CONTENT_KEY))
            && (!IA_ISREG (filler->stbuf->ia_type)))
                ignore = _gf_true;
out:
        return ignore;
}
Beispiel #4
0
struct glfs_fd *
glfs_h_open (struct glfs *fs, struct glfs_object *object, int flags)
{
	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) {
		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;
	}

	/* check types to open */
	if (IA_ISDIR (inode->ia_type)) {
		ret = -1;
		errno = EISDIR;
		goto out;
	}

	if (!IA_ISREG (inode->ia_type)) {
		ret = -1;
		errno = EINVAL;
		goto out;
	}

	glfd = glfs_fd_new (fs);
	if (!glfd) {
		errno = ENOMEM;
		goto out;
	}

	glfd->fd = fd_create (inode, getpid());
	if (!glfd->fd) {
		ret = -1;
		errno = ENOMEM;
		goto out;
	}

	/* populate loc */
	GLFS_LOC_FILL_INODE (inode, loc, out);

	/* fop/op */
	ret = syncop_open (subvol, &loc, flags, 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 {
		glfd->fd->flags = flags;
		fd_bind (glfd->fd);
		glfs_fd_bind (glfd);
	}

	glfs_subvol_done (fs, subvol);

	return glfd;
}