diff options
author | Raghavendra G <raghavendra@zresearch.com> | 2009-06-04 06:14:31 +0000 |
---|---|---|
committer | Anand V. Avati <avati@dev.gluster.com> | 2009-06-11 06:29:17 -0700 |
commit | 100a64f457a901bffe6d2d6d3b258fa193cb8517 (patch) | |
tree | 2fe69f87d7dab6ce44e8449cd967239fe89408d8 /xlators/performance | |
parent | bf76a04af4862554d6163c43a863afb59a39aafe (diff) |
read-ahead: return with error code EBADF for fops on fds without file set in their context.
- since a successful open/create will _always_ set a pointer to ra_file_t in
context of fd, this fix makes sense.
- an example of operations on bad fd can be afr sending read on the child
which was down during open.
Signed-off-by: Anand V. Avati <avati@dev.gluster.com>
Diffstat (limited to 'xlators/performance')
-rw-r--r-- | xlators/performance/read-ahead/src/read-ahead.c | 56 |
1 files changed, 45 insertions, 11 deletions
diff --git a/xlators/performance/read-ahead/src/read-ahead.c b/xlators/performance/read-ahead/src/read-ahead.c index 24a10eea04d..b2703ad8d46 100644 --- a/xlators/performance/read-ahead/src/read-ahead.c +++ b/xlators/performance/read-ahead/src/read-ahead.c @@ -432,6 +432,13 @@ ra_readv (call_frame_t *frame, xlator_t *this, fd_t *fd, size_t size, ret = fd_ctx_get (fd, this, &tmp_file); file = (ra_file_t *)(long)tmp_file; + if (file == NULL) { + op_errno = EBADF; + gf_log (this->name, GF_LOG_DEBUG, "readv received on fd with no" + " file set in its context"); + goto unwind; + } + if (file->offset != offset) { gf_log (this->name, GF_LOG_DEBUG, "unexpected offset (%"PRId64" != %"PRId64") resetting", @@ -516,19 +523,28 @@ ra_flush (call_frame_t *frame, xlator_t *this, fd_t *fd) ra_file_t *file = NULL; int ret = 0; uint64_t tmp_file = 0; + int32_t op_errno = 0; ret = fd_ctx_get (fd, this, &tmp_file); file = (ra_file_t *)(long)tmp_file; + if (file == NULL) { + op_errno = EBADF; + gf_log (this->name, GF_LOG_DEBUG, "flush received on fd with no" + " file set in its context"); + goto unwind; + } - if (file) { - flush_region (frame, file, 0, file->pages.prev->offset+1); - } + flush_region (frame, file, 0, file->pages.prev->offset+1); STACK_WIND (frame, ra_flush_cbk, FIRST_CHILD (this), FIRST_CHILD (this)->fops->flush, fd); return 0; + +unwind: + STACK_UNWIND (frame, -1, op_errno); + return 0; } @@ -538,9 +554,16 @@ ra_fsync (call_frame_t *frame, xlator_t *this, fd_t *fd, int32_t datasync) ra_file_t *file = NULL; int ret = 0; uint64_t tmp_file = 0; + int32_t op_errno = 0; ret = fd_ctx_get (fd, this, &tmp_file); file = (ra_file_t *)(long)tmp_file; + if (file == NULL) { + op_errno = EBADF; + gf_log (this->name, GF_LOG_DEBUG, "fsync received on fd with no" + " file set in its context"); + goto unwind; + } if (file) { flush_region (frame, file, 0, file->pages.prev->offset+1); @@ -551,6 +574,10 @@ ra_fsync (call_frame_t *frame, xlator_t *this, fd_t *fd, int32_t datasync) FIRST_CHILD (this)->fops->fsync, fd, datasync); return 0; + +unwind: + STACK_UNWIND (frame, -1, op_errno); + return 0; } @@ -568,9 +595,7 @@ ra_writev_cbk (call_frame_t *frame, void *cookie, xlator_t *this, ret = fd_ctx_get (fd, this, &tmp_file); file = (ra_file_t *)(long)tmp_file; - if (file) { - flush_region (frame, file, 0, file->pages.prev->offset+1); - } + flush_region (frame, file, 0, file->pages.prev->offset+1); frame->local = NULL; STACK_UNWIND (frame, op_ret, op_errno, stbuf); @@ -585,16 +610,21 @@ ra_writev (call_frame_t *frame, xlator_t *this, fd_t *fd, struct iovec *vector, ra_file_t *file = NULL; int ret = 0; uint64_t tmp_file = 0; + int32_t op_errno = 0; ret = fd_ctx_get (fd, this, &tmp_file); file = (ra_file_t *)(long)tmp_file; + if (file == NULL) { + op_errno = EBADF; + gf_log (this->name, GF_LOG_DEBUG, "writev received on fd with" + "no file set in its context"); + goto unwind; + } - if (file) { - flush_region (frame, file, 0, file->pages.prev->offset+1); + flush_region (frame, file, 0, file->pages.prev->offset+1); - /* reset the read-ahead counters too */ - file->expected = file->page_count = 0; - } + /* reset the read-ahead counters too */ + file->expected = file->page_count = 0; frame->local = fd; @@ -604,6 +634,10 @@ ra_writev (call_frame_t *frame, xlator_t *this, fd_t *fd, struct iovec *vector, fd, vector, count, offset, iobref); return 0; + +unwind: + STACK_UNWIND (frame, -1, op_errno, NULL); + return 0; } |