[sheepdog] [PATCH 2/4 v3] sheep: refactor functions shared by store_driver
Saeki Masaki
saeki.masaki at po.ntts.co.jp
Fri Mar 20 10:39:06 CET 2015
This change is a preparation patch for add store_driver.
move the definition of functions that are shared by store_driver
Signed-off-by: Masaki Saeki <saeki.masaki at po.ntts.co.jp>
---
sheep/sheep_priv.h | 4 ++
sheep/store/common.c | 86 +++++++++++++++++++++++++++++++++++++++++++++
sheep/store/plain_store.c | 83 -------------------------------------------
3 files changed, 90 insertions(+), 83 deletions(-)
diff --git a/sheep/sheep_priv.h b/sheep/sheep_priv.h
index 26afa89..e58901f 100644
--- a/sheep/sheep_priv.h
+++ b/sheep/sheep_priv.h
@@ -401,6 +401,10 @@ int leave_cluster(void);
void queue_cluster_request(struct request *req);
+int prepare_iocb(uint64_t oid, const struct siocb *iocb, bool create);
+int err_to_sderr(const char *path, uint64_t oid, int err);
+int discard(int fd, uint64_t start, uint32_t end);
+
int update_epoch_log(uint32_t epoch, struct sd_node *nodes, size_t nr_nodes);
int inc_and_log_epoch(void);
diff --git a/sheep/store/common.c b/sheep/store/common.c
index 8843fb8..8959392 100644
--- a/sheep/store/common.c
+++ b/sheep/store/common.c
@@ -9,6 +9,9 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#include <libgen.h>
+#include <linux/falloc.h>
+
#include "sheep_priv.h"
char *obj_path;
@@ -17,6 +20,88 @@ char *epoch_path;
struct store_driver *sd_store;
LIST_HEAD(store_drivers);
+#ifndef FALLOC_FL_PUNCH_HOLE
+#define FALLOC_FL_PUNCH_HOLE 0x02
+#endif
+
+#define sector_algined(x) ({ ((x) & (SECTOR_SIZE - 1)) == 0; })
+
+static inline bool iocb_is_aligned(const struct siocb *iocb)
+{
+ return sector_algined(iocb->offset) && sector_algined(iocb->length);
+}
+
+int prepare_iocb(uint64_t oid, const struct siocb *iocb, bool create)
+{
+ int syncflag = create ? O_SYNC : O_DSYNC;
+ int flags = syncflag | O_RDWR;
+
+ if (uatomic_is_true(&sys->use_journal) || sys->nosync == true)
+ flags &= ~syncflag;
+
+ if (sys->backend_dio && iocb_is_aligned(iocb)) {
+ if (!is_aligned_to_pagesize(iocb->buf))
+ panic("Memory isn't aligned to pagesize %p", iocb->buf);
+ flags |= O_DIRECT;
+ }
+
+ if (create)
+ flags |= O_CREAT | O_EXCL;
+
+ return flags;
+}
+
+int err_to_sderr(const char *path, uint64_t oid, int err)
+{
+ struct stat s;
+ char p[PATH_MAX], *dir;
+
+ /* Use a temporary buffer since dirname() may modify its argument. */
+ pstrcpy(p, sizeof(p), path);
+ dir = dirname(p);
+
+ sd_debug("%s", path);
+ switch (err) {
+ case ENOENT:
+ if (stat(dir, &s) < 0) {
+ sd_err("%s corrupted", dir);
+ return md_handle_eio(dir);
+ }
+ sd_debug("object %016" PRIx64 " not found locally", oid);
+ return SD_RES_NO_OBJ;
+ case ENOSPC:
+ /* TODO: stop automatic recovery */
+ sd_err("diskfull, oid=%"PRIx64, oid);
+ return SD_RES_NO_SPACE;
+ case EMFILE:
+ case ENFILE:
+ case EINTR:
+ case EAGAIN:
+ case EEXIST:
+ sd_err("%m, oid=%"PRIx64, oid);
+ /* make gateway try again */
+ return SD_RES_NETWORK_ERROR;
+ default:
+ sd_err("oid=%"PRIx64", %m", oid);
+ return md_handle_eio(dir);
+ }
+}
+
+int discard(int fd, uint64_t start, uint32_t end)
+{
+ int ret = xfallocate(fd, FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE,
+ start, end - start);
+ if (ret < 0) {
+ if (errno == ENOSYS || errno == EOPNOTSUPP)
+ sd_info("FALLOC_FL_PUNCH_HOLE is not supported "
+ "on this filesystem");
+ else
+ sd_err("failed to discard object, %m");
+ }
+
+ return ret;
+}
+
int update_epoch_log(uint32_t epoch, struct sd_node *nodes, size_t nr_nodes)
{
int ret, len, nodes_len;
@@ -509,3 +594,4 @@ int sd_dec_object_refcnt(uint64_t data_oid, uint32_t generation,
return ret;
}
+
diff --git a/sheep/store/plain_store.c b/sheep/store/plain_store.c
index 4c19832..0239684 100644
--- a/sheep/store/plain_store.c
+++ b/sheep/store/plain_store.c
@@ -10,41 +10,9 @@
*/
#include <libgen.h>
-#include <linux/falloc.h>
#include "sheep_priv.h"
-#ifndef FALLOC_FL_PUNCH_HOLE
-#define FALLOC_FL_PUNCH_HOLE 0x02
-#endif
-
-#define sector_algined(x) ({ ((x) & (SECTOR_SIZE - 1)) == 0; })
-
-static inline bool iocb_is_aligned(const struct siocb *iocb)
-{
- return sector_algined(iocb->offset) && sector_algined(iocb->length);
-}
-
-static int prepare_iocb(uint64_t oid, const struct siocb *iocb, bool create)
-{
- int syncflag = create ? O_SYNC : O_DSYNC;
- int flags = syncflag | O_RDWR;
-
- if (uatomic_is_true(&sys->use_journal) || sys->nosync == true)
- flags &= ~syncflag;
-
- if (sys->backend_dio && iocb_is_aligned(iocb)) {
- if (!is_aligned_to_pagesize(iocb->buf))
- panic("Memory isn't aligned to pagesize %p", iocb->buf);
- flags |= O_DIRECT;
- }
-
- if (create)
- flags |= O_CREAT | O_EXCL;
-
- return flags;
-}
-
static int get_store_path(uint64_t oid, uint8_t ec_index, char *path)
{
if (is_erasure_oid(oid)) {
@@ -90,57 +58,6 @@ bool default_exist(uint64_t oid, uint8_t ec_index)
return md_exist(oid, ec_index, path);
}
-static int err_to_sderr(const char *path, uint64_t oid, int err)
-{
- struct stat s;
- char p[PATH_MAX], *dir;
-
- /* Use a temporary buffer since dirname() may modify its argument. */
- pstrcpy(p, sizeof(p), path);
- dir = dirname(p);
-
- sd_debug("%s", path);
- switch (err) {
- case ENOENT:
- if (stat(dir, &s) < 0) {
- sd_err("%s corrupted", dir);
- return md_handle_eio(dir);
- }
- sd_debug("object %016" PRIx64 " not found locally", oid);
- return SD_RES_NO_OBJ;
- case ENOSPC:
- /* TODO: stop automatic recovery */
- sd_err("diskfull, oid=%"PRIx64, oid);
- return SD_RES_NO_SPACE;
- case EMFILE:
- case ENFILE:
- case EINTR:
- case EAGAIN:
- case EEXIST:
- sd_err("%m, oid=%"PRIx64, oid);
- /* make gateway try again */
- return SD_RES_NETWORK_ERROR;
- default:
- sd_err("oid=%"PRIx64", %m", oid);
- return md_handle_eio(dir);
- }
-}
-
-static int discard(int fd, uint64_t start, uint32_t end)
-{
- int ret = xfallocate(fd, FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE,
- start, end - start);
- if (ret < 0) {
- if (errno == ENOSYS || errno == EOPNOTSUPP)
- sd_info("FALLOC_FL_PUNCH_HOLE is not supported "
- "on this filesystem");
- else
- sd_err("failed to discard object, %m");
- }
-
- return ret;
-}
-
/* Trim zero blocks of the beginning and end of the object. */
static int default_trim(int fd, uint64_t oid, const struct siocb *iocb,
uint64_t *poffset, uint32_t *plen)
--
1.7.1
More information about the sheepdog
mailing list