bake-bulk-rpc.c 2.48 KB
Newer Older
Philip Carns's avatar
Philip Carns committed
1
2
3
4
5
6
7
/*
 * (C) 2015 The University of Chicago
 * 
 * See COPYRIGHT in top-level directory.
 */

#include <assert.h>
Philip Carns's avatar
Philip Carns committed
8
9
#include <libpmemobj.h>

Philip Carns's avatar
Philip Carns committed
10
11
#include "bake-bulk-rpc.h"

Philip Carns's avatar
Philip Carns committed
12
13
14
15
16
/* TODO: this should not be global in the long run; server may provide access
 * to multiple targets
 */
extern PMEMobjpool *pmem_pool;

Philip Carns's avatar
Philip Carns committed
17
/* service a remote RPC that instructs the server daemon to shut down */
18
static void bake_bulk_shutdown_ult(hg_handle_t handle)
Philip Carns's avatar
Philip Carns committed
19
20
21
22
23
{
    hg_return_t hret;
    struct hg_info *hgi;
    margo_instance_id mid;

24
    printf("Got RPC request to shutdown.\n");
Philip Carns's avatar
Philip Carns committed
25

26
    hgi = HG_Get_info(handle);
Philip Carns's avatar
Philip Carns committed
27
28
29
    assert(hgi);
    mid = margo_hg_class_to_instance(hgi->hg_class);

30
    hret = margo_respond(mid, handle, NULL);
Philip Carns's avatar
Philip Carns committed
31
32
    assert(hret == HG_SUCCESS);

33
    HG_Destroy(handle);
Philip Carns's avatar
Philip Carns committed
34
35
36
37
38
39
40
41
42
43

    /* NOTE: we assume that the server daemon is using
     * margo_wait_for_finalize() to suspend until this RPC executes, so there
     * is no need to send any extra signal to notify it.
     */
    margo_finalize(mid);

    return;
}
DEFINE_MARGO_RPC_HANDLER(bake_bulk_shutdown_ult)
44
45
46
47
48

/* service a remote RPC that creates a bulk region */
static void bake_bulk_create_ult(hg_handle_t handle)
{
    bake_bulk_create_out_t out;
Philip Carns's avatar
Philip Carns committed
49
50
51
    bake_bulk_create_in_t in;
    PMEMoid oid;
    hg_return_t hret;
52
53

    printf("Got RPC request to create bulk region.\n");
Philip Carns's avatar
Philip Carns committed
54
    
55
56
    memset(&out, 0, sizeof(out));

Philip Carns's avatar
Philip Carns committed
57
58
59
60
61
62
63
64
    hret = HG_Get_input(handle, &in);
    if(hret != HG_SUCCESS)
    {
        out.ret = -1;
        HG_Respond(handle, NULL, NULL, &out);
        HG_Destroy(handle);
        return;
    }
65

Philip Carns's avatar
Philip Carns committed
66
67
68
69
70
71
    out.ret = pmemobj_alloc(pmem_pool, &oid, in.region_size, 0, NULL, NULL);
    if(out.ret == 0)
    {
        /* TODO: real translation functions for opaque type */
        memcpy(&out.rid, &oid, sizeof(oid));
    }
72

Philip Carns's avatar
Philip Carns committed
73
74
    HG_Respond(handle, NULL, NULL, &out);
    HG_Destroy(handle);
75
76
77
78
    return;
}
DEFINE_MARGO_RPC_HANDLER(bake_bulk_create_ult)

79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/* service a remote RPC that writes to a bulk region */
static void bake_bulk_write_ult(hg_handle_t handle)
{
    bake_bulk_write_out_t out;
    bake_bulk_write_in_t in;
    hg_return_t hret;

    printf("Got RPC request to write bulk region.\n");
    
    memset(&out, 0, sizeof(out));

    hret = HG_Get_input(handle, &in);
    if(hret != HG_SUCCESS)
    {
        out.ret = -1;
        HG_Respond(handle, NULL, NULL, &out);
        HG_Destroy(handle);
        return;
    }

    /* TODO: implement */
    out.ret = -1;

    HG_Respond(handle, NULL, NULL, &out);
    HG_Destroy(handle);
    return;
}
DEFINE_MARGO_RPC_HANDLER(bake_bulk_write_ult)