Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/dgilbert-gitlab/tags/pull-virti…
Browse files Browse the repository at this point in the history
…ofs-20210506' into staging

virtiofsd pull 2021-05-06

A pile of cleanups:

  Use of glib allocators from Mahmoud
  Virtio spec compliance and printf cleanup from me.
  Sugar to turn on xattr when defining xattr mapping from Carlos
  an assert cleanup from Greg

Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>

# gpg: Signature made Thu 06 May 2021 19:54:18 BST
# gpg:                using RSA key 45F5C71B4A0CB7FB977A9FA90516331EBC5BFDE7
# gpg: Good signature from "Dr. David Alan Gilbert (RH2) <dgilbert@redhat.com>" [full]
# Primary key fingerprint: 45F5 C71B 4A0C B7FB 977A  9FA9 0516 331E BC5B FDE7

* remotes/dgilbert-gitlab/tags/pull-virtiofs-20210506:
  virtiofsd/fuse_virtio.c: Changed allocations of locals to GLib
  virtiofsd/passthrough_ll.c: Changed local allocations to GLib functions
  virtiofsd: Changed allocations of fv_VuDev & its internals to GLib functions
  virtiofsd: Changed allocation of lo_map_elems to GLib's functions
  virtiofsd: Changed allocations of fuse_session to GLib's functions
  virtiofsd: Changed allocations of iovec to GLib's functions
  virtiofsd: Changed allocations of fuse_req to GLib functions
  virtiofsd: Don't assume header layout
  virtiofs: Fixup printf args
  virtiofsd: Add help for -o xattr-mapping
  virtiofsd: Allow use "-o xattrmap" without "-o xattr"
  virtiofsd: Fix side-effect in assert()

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
  • Loading branch information
pm215 committed May 11, 2021
2 parents e4f3ede + 67a010f commit f9a576a
Show file tree
Hide file tree
Showing 4 changed files with 139 additions and 100 deletions.
43 changes: 18 additions & 25 deletions tools/virtiofsd/fuse_lowlevel.c
Expand Up @@ -106,7 +106,7 @@ static void list_add_req(struct fuse_req *req, struct fuse_req *next)
static void destroy_req(fuse_req_t req)
{
pthread_mutex_destroy(&req->lock);
free(req);
g_free(req);
}

void fuse_free_req(fuse_req_t req)
Expand All @@ -130,7 +130,7 @@ static struct fuse_req *fuse_ll_alloc_req(struct fuse_session *se)
{
struct fuse_req *req;

req = (struct fuse_req *)calloc(1, sizeof(struct fuse_req));
req = g_try_new0(struct fuse_req, 1);
if (req == NULL) {
fuse_log(FUSE_LOG_ERR, "fuse: failed to allocate request\n");
} else {
Expand Down Expand Up @@ -217,9 +217,9 @@ static int send_reply(fuse_req_t req, int error, const void *arg,
int fuse_reply_iov(fuse_req_t req, const struct iovec *iov, int count)
{
int res;
struct iovec *padded_iov;
g_autofree struct iovec *padded_iov = NULL;

padded_iov = malloc((count + 1) * sizeof(struct iovec));
padded_iov = g_try_new(struct iovec, count + 1);
if (padded_iov == NULL) {
return fuse_reply_err(req, ENOMEM);
}
Expand All @@ -228,7 +228,6 @@ int fuse_reply_iov(fuse_req_t req, const struct iovec *iov, int count)
count++;

res = send_reply_iov(req, 0, padded_iov, count);
free(padded_iov);

return res;
}
Expand Down Expand Up @@ -568,7 +567,7 @@ static struct fuse_ioctl_iovec *fuse_ioctl_iovec_copy(const struct iovec *iov,
struct fuse_ioctl_iovec *fiov;
size_t i;

fiov = malloc(sizeof(fiov[0]) * count);
fiov = g_try_new(struct fuse_ioctl_iovec, count);
if (!fiov) {
return NULL;
}
Expand All @@ -586,8 +585,8 @@ int fuse_reply_ioctl_retry(fuse_req_t req, const struct iovec *in_iov,
size_t out_count)
{
struct fuse_ioctl_out arg;
struct fuse_ioctl_iovec *in_fiov = NULL;
struct fuse_ioctl_iovec *out_fiov = NULL;
g_autofree struct fuse_ioctl_iovec *in_fiov = NULL;
g_autofree struct fuse_ioctl_iovec *out_fiov = NULL;
struct iovec iov[4];
size_t count = 1;
int res;
Expand All @@ -603,13 +602,14 @@ int fuse_reply_ioctl_retry(fuse_req_t req, const struct iovec *in_iov,
/* Can't handle non-compat 64bit ioctls on 32bit */
if (sizeof(void *) == 4 && req->ioctl_64bit) {
res = fuse_reply_err(req, EINVAL);
goto out;
return res;
}

if (in_count) {
in_fiov = fuse_ioctl_iovec_copy(in_iov, in_count);
if (!in_fiov) {
goto enomem;
res = fuse_reply_err(req, ENOMEM);
return res;
}

iov[count].iov_base = (void *)in_fiov;
Expand All @@ -619,7 +619,8 @@ int fuse_reply_ioctl_retry(fuse_req_t req, const struct iovec *in_iov,
if (out_count) {
out_fiov = fuse_ioctl_iovec_copy(out_iov, out_count);
if (!out_fiov) {
goto enomem;
res = fuse_reply_err(req, ENOMEM);
return res;
}

iov[count].iov_base = (void *)out_fiov;
Expand All @@ -628,15 +629,8 @@ int fuse_reply_ioctl_retry(fuse_req_t req, const struct iovec *in_iov,
}

res = send_reply_iov(req, 0, iov, count);
out:
free(in_fiov);
free(out_fiov);

return res;

enomem:
res = fuse_reply_err(req, ENOMEM);
goto out;
}

int fuse_reply_ioctl(fuse_req_t req, int result, const void *buf, size_t size)
Expand All @@ -663,11 +657,11 @@ int fuse_reply_ioctl(fuse_req_t req, int result, const void *buf, size_t size)
int fuse_reply_ioctl_iov(fuse_req_t req, int result, const struct iovec *iov,
int count)
{
struct iovec *padded_iov;
g_autofree struct iovec *padded_iov = NULL;
struct fuse_ioctl_out arg;
int res;

padded_iov = malloc((count + 2) * sizeof(struct iovec));
padded_iov = g_try_new(struct iovec, count + 2);
if (padded_iov == NULL) {
return fuse_reply_err(req, ENOMEM);
}
Expand All @@ -680,7 +674,6 @@ int fuse_reply_ioctl_iov(fuse_req_t req, int result, const struct iovec *iov,
memcpy(&padded_iov[2], iov, count * sizeof(struct iovec));

res = send_reply_iov(req, 0, padded_iov, count + 2);
free(padded_iov);

return res;
}
Expand Down Expand Up @@ -1684,7 +1677,7 @@ static struct fuse_req *check_interrupt(struct fuse_session *se,
if (curr->u.i.unique == req->unique) {
req->interrupted = 1;
list_del_req(curr);
free(curr);
g_free(curr);
return NULL;
}
}
Expand Down Expand Up @@ -2477,7 +2470,7 @@ void fuse_session_destroy(struct fuse_session *se)
free(se->vu_socket_path);
se->vu_socket_path = NULL;

free(se);
g_free(se);
}


Expand All @@ -2500,7 +2493,7 @@ struct fuse_session *fuse_session_new(struct fuse_args *args,
return NULL;
}

se = (struct fuse_session *)calloc(1, sizeof(struct fuse_session));
se = g_try_new0(struct fuse_session, 1);
if (se == NULL) {
fuse_log(FUSE_LOG_ERR, "fuse: failed to allocate fuse object\n");
goto out1;
Expand Down Expand Up @@ -2560,7 +2553,7 @@ struct fuse_session *fuse_session_new(struct fuse_args *args,
out4:
fuse_opt_free_args(args);
out2:
free(se);
g_free(se);
out1:
return NULL;
}
Expand Down

0 comments on commit f9a576a

Please sign in to comment.