From b600fc854d2a813dc7cf08eb58590ada90db4c02 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Wed, 3 Jul 2013 07:32:52 +0000 Subject: file: embed ioq in the opened mog_file object This allows us to avoid a redundant hash lookup every time we "activate" an open file for reading or writing. --- Makefile.am | 1 - cmogstored.h | 1 + file.c | 35 +++++++++++++++++++---------------- fsck_queue.c | 19 ------------------- http.c | 6 +++--- mgmt.c | 8 +++++++- 6 files changed, 30 insertions(+), 40 deletions(-) delete mode 100644 fsck_queue.c diff --git a/Makefile.am b/Makefile.am index 0b24b7b..494bfa8 100644 --- a/Makefile.am +++ b/Makefile.am @@ -40,7 +40,6 @@ mog_src += fdmap.h mog_src += file.c mog_src += fs.c mog_src += fs.h -mog_src += fsck_queue.c mog_src += gcc.h mog_src += http.c mog_src += http.h diff --git a/cmogstored.h b/cmogstored.h index 7d32817..c12234b 100644 --- a/cmogstored.h +++ b/cmogstored.h @@ -273,6 +273,7 @@ struct mog_file { size_t pathlen; char *tmppath; /* NULL-ed if rename()-ed away */ void *mmptr; + struct mog_ioq *ioq; struct mog_svc *svc; struct mog_digest digest; }; diff --git a/file.c b/file.c index bd47537..1caab91 100644 --- a/file.c +++ b/file.c @@ -17,12 +17,24 @@ bool mog_open_expire_retry(struct mog_svc *svc) return false; } +static struct mog_fd *mog_file_init_common(int fd, struct mog_svc *svc) +{ + struct mog_fd *mfd = mog_fd_init(fd, MOG_FD_TYPE_FILE); + struct mog_file *file; + + file = &mfd->as.file; + memset(file, 0, sizeof(struct mog_file)); + file->svc = svc; + file->ioq = mog_ioq_current; + + return mfd; +} + /* path must be a free()-able pointer */ struct mog_fd * mog_file_open_read(struct mog_svc *svc, char *path) { struct mog_fd *mfd; - struct mog_file *mfile; int fd = mog_open_read(svc, path); if (fd < 0 && mog_open_expire_retry(svc)) @@ -30,12 +42,8 @@ mog_file_open_read(struct mog_svc *svc, char *path) if (fd < 0) return NULL; - mfd = mog_fd_init(fd, MOG_FD_TYPE_FILE); - - mfile = &mfd->as.file; - memset(mfile, 0, sizeof(struct mog_file)); - mfile->fsize = -1; - mfile->svc = svc; + mfd = mog_file_init_common(fd, svc); + mfd->as.file.fsize = -1; return mfd; } @@ -61,8 +69,6 @@ static int mkpath_open_put(struct mog_svc *svc, char *path, int flags) struct mog_fd * mog_file_open_put(struct mog_svc *svc, char *path, int flags) { - struct mog_fd *mfd; - struct mog_file *mfile; int fd = mkpath_open_put(svc, path, flags); if (fd < 0 && mog_open_expire_retry(svc)) @@ -70,18 +76,13 @@ mog_file_open_put(struct mog_svc *svc, char *path, int flags) if (fd < 0) return NULL; - mfd = mog_fd_init(fd, MOG_FD_TYPE_FILE); - - mfile = &mfd->as.file; - memset(mfile, 0, sizeof(struct mog_file)); - mfile->svc = svc; - - return mfd; + return mog_file_init_common(fd, svc); } void mog_file_close(struct mog_fd *mfd) { struct mog_file *mfile = &mfd->as.file; + struct mog_ioq *ioq; assert(mfd->fd_type == MOG_FD_TYPE_FILE && "mog_fd is not a file"); @@ -90,5 +91,7 @@ void mog_file_close(struct mog_fd *mfd) free(mfile->tmppath); mog_digest_destroy(&mfile->digest); + ioq = mfile->ioq; mog_fd_put(mfd); + mog_ioq_next(ioq); } diff --git a/fsck_queue.c b/fsck_queue.c deleted file mode 100644 index b0895cf..0000000 --- a/fsck_queue.c +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright (C) 2012-2013, Eric Wong - * License: GPLv3 or later (see COPYING for details) - */ -#include "cmogstored.h" - -bool mog_fsck_queue_ready(struct mog_fd *mfd) -{ - struct mog_mgmt *mgmt = &mfd->as.mgmt; - struct mog_dev *dev = mog_dev_for(mgmt->svc, mgmt->mog_devid, false); - - /* we may have been called to fsck a file NOT for MogileFS ... */ - if (dev == NULL) - return true; - - assert(mgmt->prio == MOG_PRIO_FSCK && "bad prio"); - - return mog_ioq_ready(&dev->fsckq, mfd); -} diff --git a/http.c b/http.c index e440d2b..3ba33bb 100644 --- a/http.c +++ b/http.c @@ -160,11 +160,11 @@ static enum mog_next http_forward_in_progress(struct mog_fd *mfd, bool needq) { struct mog_http *http = &mfd->as.http; enum mog_http_method method = http->_p.http_method; - struct mog_dev *dev; if (needq) { - dev = mog_dev_for(http->svc, http->_p.mog_devid, false); - if (dev && !mog_ioq_ready(&dev->ioq, mfd)) + struct mog_file *file = &http->forward->as.file; + + if (file->ioq && !mog_ioq_ready(file->ioq, mfd)) /* no need to setup/stash rbuf, it's been done */ return MOG_NEXT_IGNORE; } diff --git a/mgmt.c b/mgmt.c index 6b8d6a6..4b8ef8b 100644 --- a/mgmt.c +++ b/mgmt.c @@ -50,10 +50,12 @@ static void mgmt_digest_step(struct mog_fd *mfd) static enum mog_next mgmt_digest_in_progress(struct mog_fd *mfd) { struct mog_mgmt *mgmt = &mfd->as.mgmt; + struct mog_file *file; assert(mgmt->forward && mgmt->forward != MOG_IOSTAT && "bad forward"); + file = &mgmt->forward->as.file; - if (mgmt->prio == MOG_PRIO_FSCK && !mog_fsck_queue_ready(mfd)) + if (file->ioq && !mog_ioq_ready(file->ioq, mfd)) return MOG_NEXT_IGNORE; mgmt_digest_step(mfd); @@ -181,6 +183,10 @@ mgmt_process_client(struct mog_fd *mfd, struct mog_rbuf *rbuf, break; case MOG_MGMT_METHOD_DIG: mog_mgmt_fn_digest(mgmt, buf); + + if (dev && mgmt->forward) + assert(mgmt->forward->as.file.ioq + && "ioq not stashed"); break; } mgmt->mgmt_method = MOG_MGMT_METHOD_NONE; -- cgit v1.2.3-24-ge0c7