All of lore.kernel.org
 help / color / mirror / Atom feed
From: trondmy@kernel.org
To: Steve Dickson <SteveD@redhat.com>
Cc: linux-nfs@vger.kernel.org
Subject: [PATCH 5/7] mountd: Ensure dump_to_cache() sets errno appropriately
Date: Thu, 16 Apr 2020 18:12:50 -0400	[thread overview]
Message-ID: <20200416221252.82102-6-trondmy@kernel.org> (raw)
In-Reply-To: <20200416221252.82102-5-trondmy@kernel.org>

From: Trond Myklebust <trond.myklebust@hammerspace.com>

cache_write() will set errno if it returns -1, so that callers can
handle errors appropriately, however dump_to_cache() needs to do
so too.

Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
---
 utils/mountd/cache.c | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)

diff --git a/utils/mountd/cache.c b/utils/mountd/cache.c
index 94e9e44b46b9..0f323226b12a 100644
--- a/utils/mountd/cache.c
+++ b/utils/mountd/cache.c
@@ -936,12 +936,13 @@ static void write_secinfo(char **bp, int *blen, struct exportent *ep, int flag_m
 
 }
 
-static int dump_to_cache(int f, char *buf, int buflen, char *domain,
+static int dump_to_cache(int f, char *buf, int blen, char *domain,
 			 char *path, struct exportent *exp, int ttl)
 {
 	char *bp = buf;
-	int blen = buflen;
 	time_t now = time(0);
+	size_t buflen;
+	ssize_t err;
 
 	if (ttl <= 1)
 		ttl = DEFAULT_TTL;
@@ -974,8 +975,18 @@ static int dump_to_cache(int f, char *buf, int buflen, char *domain,
 	} else
 		qword_adduint(&bp, &blen, now + ttl);
 	qword_addeol(&bp, &blen);
-	if (blen <= 0) return -1;
-	if (cache_write(f, buf, bp - buf) != bp - buf) return -1;
+	if (blen <= 0) {
+		errno = ENOBUFS;
+		return -1;
+	}
+	buflen = bp - buf;
+	err = cache_write(f, buf, buflen);
+	if (err < 0)
+		return err;
+	if ((size_t)err != buflen) {
+		errno = ENOSPC;
+		return -1;
+	}
 	return 0;
 }
 
-- 
2.25.2


  reply	other threads:[~2020-04-16 22:15 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-16 22:12 [PATCH 0/7] nfs-utils fixes trondmy
2020-04-16 22:12 ` [PATCH 1/7] mountd: Add a helper nfsd_path_statfs64() for uuid_by_path() trondmy
2020-04-16 22:12   ` [PATCH 2/7] nfsd: Support running nfsd_name_to_handle_at() in the root jail trondmy
2020-04-16 22:12     ` [PATCH 3/7] mountd: Fix up path checking helper same_path() trondmy
2020-04-16 22:12       ` [PATCH 4/7] Fix autoconf probe for 'struct nfs_filehandle' trondmy
2020-04-16 22:12         ` trondmy [this message]
2020-04-16 22:12           ` [PATCH 6/7] mountd: Ignore transient and non-fatal filesystem errors in nfsd_fh() trondmy
2020-04-16 22:12             ` [PATCH 7/7] mountd: Check the stat() return values in match_fsid() trondmy
2020-04-27 18:38             ` [PATCH 6/7] mountd: Ignore transient and non-fatal filesystem errors in nfsd_fh() J. Bruce Fields
2020-04-27 18:39               ` J. Bruce Fields
2020-05-08 14:13 ` [PATCH 0/7] nfs-utils fixes Steve Dickson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200416221252.82102-6-trondmy@kernel.org \
    --to=trondmy@kernel.org \
    --cc=SteveD@redhat.com \
    --cc=linux-nfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.