* [PATCH] do not die on OOM when for mgmt paths
@ 2015-08-23 21:00 Eric Wong
0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2015-08-23 21:00 UTC (permalink / raw)
To: cmogstored-public
This also makes trywrite OOM-aware and will simulate a write error
on allocation.
---
mgmt_fn.c | 11 ++++++++++-
trywrite.c | 8 ++++++--
2 files changed, 16 insertions(+), 3 deletions(-)
diff --git a/mgmt_fn.c b/mgmt_fn.c
index c0d4571..a07fa60 100644
--- a/mgmt_fn.c
+++ b/mgmt_fn.c
@@ -17,7 +17,16 @@ get_path(struct iovec *dst, struct mog_mgmt *mgmt, char *buf, bool sdup)
char *path;
if (sdup) {
- path = xmalloc(dst->iov_len + 1);
+ path = malloc(dst->iov_len + 1);
+ if (!path) {
+ struct iovec iov;
+
+ IOV_STR(&iov, "ERROR: out-of-memory\r\n");
+ mog_mgmt_writev(mgmt, &iov, 1);
+
+ return NULL;
+ }
+
memcpy(path, dst->iov_base, dst->iov_len);
} else {
path = dst->iov_base;
diff --git a/trywrite.c b/trywrite.c
index c872609..7ade425 100644
--- a/trywrite.c
+++ b/trywrite.c
@@ -12,10 +12,14 @@ struct mog_wbuf {
static void * wbuf_newv(size_t total, struct iovec *iov, int iovcnt)
{
- struct mog_wbuf *wbuf = xmalloc(sizeof(struct mog_wbuf) + total);
- void *dst = wbuf->buf;
+ struct mog_wbuf *wbuf = malloc(sizeof(struct mog_wbuf) + total);
+ void *dst;
int i;
+ if (!wbuf) return MOG_WR_ERROR;
+
+ dst = wbuf->buf;
+
wbuf->len = total;
wbuf->off = 0;
--
EW
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2015-08-23 21:00 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-08-23 21:00 [PATCH] do not die on OOM when for mgmt paths Eric Wong
Code repositories for project(s) associated with this public inbox
https://yhbt.net/cmogstored.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).