[RFC 13/32] mars: add new module xio
Signed-off-by: Thomas Schoebel-Theuer--- drivers/staging/mars/xio_bricks/xio.c | 227 include/linux/xio/xio.h | 319 ++ 2 files changed, 546 insertions(+) create mode 100644 drivers/staging/mars/xio_bricks/xio.c create mode 100644 include/linux/xio/xio.h diff --git a/drivers/staging/mars/xio_bricks/xio.c b/drivers/staging/mars/xio_bricks/xio.c new file mode 100644 index ..e58f11f497f9 --- /dev/null +++ b/drivers/staging/mars/xio_bricks/xio.c @@ -0,0 +1,227 @@ +/* + * MARS Long Distance Replication Software + * + * Copyright (C) 2010-2014 Thomas Schoebel-Theuer + * Copyright (C) 2011-2014 1&1 Internet AG + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include +#include +#include +#include +#include +#include + +#include + +// + +/* infrastructure */ + +struct banning xio_global_ban = {}; +atomic_t xio_global_io_flying = ATOMIC_INIT(0); + +// + +/* object stuff */ + +const struct generic_object_type aio_type = { + .object_type_name = "aio", + .default_size = sizeof(struct aio_object), + .object_type_nr = OBJ_TYPE_AIO, +}; + +// + +/* brick stuff */ + +/***/ + +/* meta descriptions */ + +const struct meta xio_info_meta[] = { + META_INI(current_size,struct xio_info, FIELD_INT), + META_INI(tf_align,struct xio_info, FIELD_INT), + META_INI(tf_min_size, struct xio_info, FIELD_INT), + {} +}; + +const struct meta xio_aio_user_meta[] = { + META_INI(_object_cb.cb_error, struct aio_object, FIELD_INT), + META_INI(io_pos, struct aio_object, FIELD_INT), + META_INI(io_len, struct aio_object, FIELD_INT), + META_INI(io_may_write,struct aio_object, FIELD_INT), + META_INI(io_prio, struct aio_object, FIELD_INT), + META_INI(io_cs_mode, struct aio_object, FIELD_INT), + META_INI(io_timeout, struct aio_object, FIELD_INT), + META_INI(io_total_size, struct aio_object, FIELD_INT), + META_INI(io_checksum, struct aio_object, FIELD_RAW), + META_INI(io_flags, struct aio_object, FIELD_INT), + META_INI(io_rw,struct aio_object, FIELD_INT), + META_INI(io_id,struct aio_object, FIELD_INT), + META_INI(io_skip_sync,struct aio_object, FIELD_INT), + {} +}; + +const struct meta xio_timespec_meta[] = { + META_INI_TRANSFER(tv_sec, struct timespec, FIELD_UINT, 8), + META_INI_TRANSFER(tv_nsec, struct timespec, FIELD_UINT, 4), + {} +}; + +// + +/* crypto stuff */ + +#include +#include + +/* 896545098777564212b9e91af4c973f094649aa7 */ +#ifndef crt_hash +#define HAS_NEW_CRYPTO +#endif + +#ifdef HAS_NEW_CRYPTO + +/* Nor now, use shash. + * Later, asynchronous support should be added for full exploitation + * of crypto hardware. + */ +#include + +static struct crypto_shash *xio_tfm; +int xio_digest_size; + +struct mars_sdesc { + struct shash_desc shash; + char ctx[]; +}; + +void xio_digest(unsigned char *digest, void *data, int len) +{ + int size = sizeof(struct mars_sdesc) + crypto_shash_descsize(xio_tfm); + struct mars_sdesc *sdesc = brick_mem_alloc(size); + int status; + + sdesc->shash.tfm = xio_tfm; + sdesc->shash.flags = 0; + + memset(digest, 0, xio_digest_size); + status = crypto_shash_digest(>shash, data, len, digest); + if (unlikely(status < 0)) + XIO_ERR( + "cannot calculate cksum on %p len=%d, status=%d\n", +data, len, +status); + + brick_mem_free(sdesc); +} + +#else /* HAS_NEW_CRYPTO */ + +/* Old implementation, to disappear. + * Was a quick'n dirty lab prototype with unnecessary + * global variables and locking. + */ + +static struct crypto_hash *xio_tfm; +static struct semaphore tfm_sem; +int xio_digest_size; + +void xio_digest(unsigned char *digest, void *data, int len) +{ + struct hash_desc desc = { + .tfm = xio_tfm, + .flags = 0, + }; + struct scatterlist sg; + + memset(digest, 0, xio_digest_size); + + /* TODO: use
[RFC 13/32] mars: add new module xio
Signed-off-by: Thomas Schoebel-Theuer --- drivers/staging/mars/xio_bricks/xio.c | 227 include/linux/xio/xio.h | 319 ++ 2 files changed, 546 insertions(+) create mode 100644 drivers/staging/mars/xio_bricks/xio.c create mode 100644 include/linux/xio/xio.h diff --git a/drivers/staging/mars/xio_bricks/xio.c b/drivers/staging/mars/xio_bricks/xio.c new file mode 100644 index ..e58f11f497f9 --- /dev/null +++ b/drivers/staging/mars/xio_bricks/xio.c @@ -0,0 +1,227 @@ +/* + * MARS Long Distance Replication Software + * + * Copyright (C) 2010-2014 Thomas Schoebel-Theuer + * Copyright (C) 2011-2014 1&1 Internet AG + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include +#include +#include +#include +#include +#include + +#include + +// + +/* infrastructure */ + +struct banning xio_global_ban = {}; +atomic_t xio_global_io_flying = ATOMIC_INIT(0); + +// + +/* object stuff */ + +const struct generic_object_type aio_type = { + .object_type_name = "aio", + .default_size = sizeof(struct aio_object), + .object_type_nr = OBJ_TYPE_AIO, +}; + +// + +/* brick stuff */ + +/***/ + +/* meta descriptions */ + +const struct meta xio_info_meta[] = { + META_INI(current_size,struct xio_info, FIELD_INT), + META_INI(tf_align,struct xio_info, FIELD_INT), + META_INI(tf_min_size, struct xio_info, FIELD_INT), + {} +}; + +const struct meta xio_aio_user_meta[] = { + META_INI(_object_cb.cb_error, struct aio_object, FIELD_INT), + META_INI(io_pos, struct aio_object, FIELD_INT), + META_INI(io_len, struct aio_object, FIELD_INT), + META_INI(io_may_write,struct aio_object, FIELD_INT), + META_INI(io_prio, struct aio_object, FIELD_INT), + META_INI(io_cs_mode, struct aio_object, FIELD_INT), + META_INI(io_timeout, struct aio_object, FIELD_INT), + META_INI(io_total_size, struct aio_object, FIELD_INT), + META_INI(io_checksum, struct aio_object, FIELD_RAW), + META_INI(io_flags, struct aio_object, FIELD_INT), + META_INI(io_rw,struct aio_object, FIELD_INT), + META_INI(io_id,struct aio_object, FIELD_INT), + META_INI(io_skip_sync,struct aio_object, FIELD_INT), + {} +}; + +const struct meta xio_timespec_meta[] = { + META_INI_TRANSFER(tv_sec, struct timespec, FIELD_UINT, 8), + META_INI_TRANSFER(tv_nsec, struct timespec, FIELD_UINT, 4), + {} +}; + +// + +/* crypto stuff */ + +#include +#include + +/* 896545098777564212b9e91af4c973f094649aa7 */ +#ifndef crt_hash +#define HAS_NEW_CRYPTO +#endif + +#ifdef HAS_NEW_CRYPTO + +/* Nor now, use shash. + * Later, asynchronous support should be added for full exploitation + * of crypto hardware. + */ +#include + +static struct crypto_shash *xio_tfm; +int xio_digest_size; + +struct mars_sdesc { + struct shash_desc shash; + char ctx[]; +}; + +void xio_digest(unsigned char *digest, void *data, int len) +{ + int size = sizeof(struct mars_sdesc) + crypto_shash_descsize(xio_tfm); + struct mars_sdesc *sdesc = brick_mem_alloc(size); + int status; + + sdesc->shash.tfm = xio_tfm; + sdesc->shash.flags = 0; + + memset(digest, 0, xio_digest_size); + status = crypto_shash_digest(>shash, data, len, digest); + if (unlikely(status < 0)) + XIO_ERR( + "cannot calculate cksum on %p len=%d, status=%d\n", +data, len, +status); + + brick_mem_free(sdesc); +} + +#else /* HAS_NEW_CRYPTO */ + +/* Old implementation, to disappear. + * Was a quick'n dirty lab prototype with unnecessary + * global variables and locking. + */ + +static struct crypto_hash *xio_tfm; +static struct semaphore tfm_sem; +int xio_digest_size; + +void xio_digest(unsigned char *digest, void *data, int len) +{ + struct hash_desc desc = { + .tfm = xio_tfm, + .flags = 0, + }; + struct scatterlist sg; + + memset(digest, 0, xio_digest_size); + + /* TODO: use per-thread instance, omit locking