[Sheepdog] [PATCH] sheep: introduce sd_op_template

MORITA Kazutaka morita.kazutaka at lab.ntt.co.jp
Wed Oct 26 05:28:48 CEST 2011


At Mon, 24 Oct 2011 15:05:08 +0900,
MORITA Kazutaka wrote:
> 
> When we want to add a new operation (SD_OP_xxxxx), it is not clear
> which codes we should modify.  And in some cases, we need to modify
> codes everywhere to implement one operation.  This is not a good
> design.
> 
> This patch abstracts out Sheepdog operations into sd_op_template, and
> moves all the request processing codes to sheep/ops.c.
> 
> The definition of sd_op_template is as follows:
> 
> struct sd_op_template {
>         enum sd_op_type type;
> 
>         int force;
> 
>         int (*process_work)(const struct sd_req *req, struct sd_rsp *rsp,
>                             void *data);
>         int (*process_main)(const struct sd_req *req, struct sd_rsp *rsp,
>                             void *data);
> };
> 
> 'type' is the type of the operation; SD_OP_TYPE_CLUSTER,
> SD_OP_TYPE_LOCAL, or SD_OP_TYPE_IO.
> 
> 'force' is set to non-zero if the operations should be processed even
> when the cluster is not working.
> 
> 'process_work()' and 'process_main()' are the main functions of this
> operation.  process_work() will be called in the worker thread, and
> process_main() will be called in the main thread.
> 
> If type is SD_OP_TYPE_CLUSTER, it is guaranteed that only one node
> processes a cluster operation at the same time.  We can use this for
> something like distributed locking.  process_work() will be called on
> the local node, and process_main() will be called on every nodes.
> 
> If type is SD_OP_TYPE_LOCAL, both process_work() and process_main()
> will be called on the local node.
> 
> If type is SD_OP_TYPE_IO, neither process_work() nor process_main() is
> used because this type of operation is heavily intertwined with
> Sheepdog core codes.  We will be unlikely to add new operations of
> this type.
> 
> Signed-off-by: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>
> ---
> 
> v2:
>  - address Yuan's comments (Thanks Yuan!)
>  - fix data_length in the response header
>  - hide struct sd_op_template into sheep/ops.c
>  - return SD_RES_INVALID_PERMS when opcode is invalid
> 
> 
>  sheep/Makefile.am  |    2 +-
>  sheep/group.c      |  286 +++----------------------------
>  sheep/ops.c        |  488 ++++++++++++++++++++++++++++++++++++++++++++++++++++
>  sheep/sdnet.c      |  113 ++----------
>  sheep/sheep_priv.h |   21 ++-
>  sheep/store.c      |   26 +--
>  6 files changed, 561 insertions(+), 375 deletions(-)
>  create mode 100644 sheep/ops.c

Applied.

Kazutaka



More information about the sheepdog mailing list