Commit 0aa41c9b authored by Alberto Miranda's avatar Alberto Miranda ♨️
Browse files

Significant improvement to API usability

Better abstraction and internal management of data
resources and storage backends
parent fb8e248c
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -29,14 +29,17 @@

#include <norns.h>

#if 0
void print_iotd(struct norns_iotd* iotdp){
    fprintf(stdout, "iotd -> struct nornds_iotd {\n");
    fprintf(stdout, "  io_taskid = %d;\n", iotdp->io_taskid);
    fprintf(stdout, "};\n");
}
#endif


int main() {
#if 0
    struct norns_iotd iotd = {
        .io_taskid = 0,
    };
@@ -52,6 +55,7 @@ int main() {
    fprintf(stdout, "norns_transfer() succeeded!\n");
    fprintf(stdout, "output from submission:\n");
    print_iotd(&iotd);
#endif

    return 0;
}
+2 −0
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@ const char* ex_hosts[5] = {

int main(int argc, char* argv[]) {

#if 0
    (void) argc;
    (void) argv;
    struct norns_cred cred;
@@ -119,5 +120,6 @@ int main(int argc, char* argv[]) {
    NORNS_PLIST_FREE(hosts1);
    NORNS_PLIST_FREE(hosts2);
    NORNS_PLIST_FREE(backends);
#endif

}
+6 −4
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@ const char* ex_hosts[5] = {

int main(int argc, char* argv[]) {

#if 0
    (void) argc;
    (void) argv;
    struct norns_cred cred;
@@ -108,15 +109,15 @@ int main(int argc, char* argv[]) {
            .in_type = NORNS_BACKEND_LOCAL_NVML,
            .in_path = {
//                .p_hostname = "node42",
                .p_hostname = NULL,
                .p_datapath = "nvm://foobar.bin",
                .p_host = NULL,
                .p_path = "nvm://foobar.bin",
            },
        },
        .io_dst = {
            .out_type = NORNS_BACKEND_LUSTRE,
            .out_path = {
                .p_hostname = "node42",
                .p_datapath = "nvm://baz.bin",
                .p_host = "node42",
                .p_path = "nvm://baz.bin",
            }
        }
    };
@@ -137,5 +138,6 @@ int main(int argc, char* argv[]) {
    NORNS_PLIST_FREE(hosts1);
    NORNS_PLIST_FREE(hosts2);
    NORNS_PLIST_FREE(backends);
#endif

}
+77 −214
Original line number Diff line number Diff line
/* * Copyright (C) 2017 Barcelona Supercomputing Center
/* * Copyright (C) 2017-2018 Barcelona Supercomputing Center
 *                           Centro Nacional de Supercomputacion
 *
 * This file is part of the Data Scheduler, a daemon for tracking and managing
@@ -24,13 +24,19 @@
#ifndef __NORNS_LIB_H__
#define __NORNS_LIB_H__ 1

#include "norns_error.h"
#include "norns_backends.h"
#ifndef NORNS_API_VERSION
#define NORNS_API_VERSION 10
#endif

#include <sys/types.h>
#include <stdint.h>
#include <assert.h>

#include "norns_types.h"
#include "norns_error.h"
#include "norns_backends.h"
#include "norns_resources.h"

#ifdef __cplusplus
extern "C" {
#endif
@@ -42,115 +48,15 @@ struct norns_cred {
    gid_t cr_gid;    /* GID of the process */
};

struct norns_membuf {
    void*  b_addr;      /* memory address */
    size_t b_size;      /* memory size */
};

#define NORNS_MEMBUFFER_INIT(addr, size) \
{ \
    .b_addr = (addr), \
    .b_size = (size) \
}

struct norns_path {
    const char* p_hostname;     /* hostname (NULL if local) */
    const char* p_datapath;     /* path to "data" (i.e. file or directory) */
};

#define NORNS_LOCAL_PATH_INIT(path) \
{ \
    .p_hostname = NULL, \
    .p_datapath = (path) \
}

#define NORNS_REMOTE_PATH_INIT(hostname, path) \
{ \
    .p_hostname = (hostname), \
    .p_datapath = (path) \
}

/* Input data resource descriptor  */
struct norns_data_in {

    // options:
    // - read from local nvm and write to lustre
    // - read from lustre and write to local nvm
    // - read from remote nvm and write to local nvm
    // - read from local nvm and write to remote nvm
    // - read from process memory and write to local nvm
    // - read from process memory and write to lustre 
    // - echofs: "read" from lustre into echofs
    // - echofs: "write" from echofs to lustre
    //
    //
    // - NEXTGenIO input resources: 
    // 1.   local nvm       nvm://path/to/dir/[file]                DAX-NVML
    // 2.   local tmpfs     tmpfs://path/to/dir/[file]              DAX-NVML
    // 3.   lustre          lustre://path/to/dir/[file]             POSIX
    // 4.   remote nvm      nvm@hostname://path/to/dir/[file]       DAX-NVML+RDMA/TCP
    // 5.   echofs          echofs://path/to/dir/[file]             CUSTOM
    // 6.   process memory  [pointer + size]                        MEMORY
    //
    // - NEXTGenIO output resources:
    // 1.   local nvm       nvm://path/to/dir/[file]                DAX-NVML
    // 2.   local tmpfs     tmpfs://path/to/dir/[file]              DAX-NVML
    // 3.   lustre (path)   lustre://path/to/dir/[file]             POSIX
    // 4.   remote nvm      nvm@hostname:://path/to/dir/[file]      DAX-NVML+RDMA/TCP
    // 5.   echofs          echofs://path/to/dir/[file]             CUSTOM

    uint32_t    in_type;         /* type of resource */
    union {
        struct norns_membuf __in_buffer;
        struct norns_path __in_path;
    } __in_location;

#define in_buffer __in_location.__in_buffer
#define in_path __in_location.__in_path
};

/* Output data resource descriptor  */
struct norns_data_out {

    // options:
    // - read from local nvm and write to lustre
    // - read from lustre and write to local nvm
    // - read from remote nvm and write to local nvm
    // - read from local nvm and write to remote nvm
    // - read from process memory and write to local nvm
    // - read from process memory and write to lustre 
    // - echofs: "read" from lustre into echofs
    // - echofs: "write" from echofs to lustre
    //
    //
    // - input resources: 
    // 1.   local nvm       nvm://path/to/dir/[file]
    // 2.   lustre          lustre://path/to/dir/[file]
    // 3.   remote nvm      nvm@hostname://path/to/dir/[file]
    // 4.   echofs          echofs://path/to/dir/[file]
    // 5.   process memory  [pointer + size]
    //
    // - output resources:
    // 1.   local nvm (path)    nvm://foobar
    // 2.   lustre (path)       lustre://foobar
    // 3.   remote nvm          nvm@hostname:://foobar
    // 4.   echofs              echofs://foobar

    uint32_t    out_type;         /* type of resource */
    struct norns_path out_path;
};


/* I/O task descriptor */
struct norns_iotd {
    uint32_t            io_taskid;     /* task identifier */
    uint32_t            io_optype;    /* operation to be performed */

    struct norns_data_in io_src;   /* data source */
    struct norns_data_out io_dst;   /* data destination */
//    struct norns_cred*  ni_auth;   /* process credentials (NULL if unprivileged) */
};
/* Descriptor for an I/O task */
typedef struct {
    norns_tid_t         t_id;   /* task identifier */
    norns_op_t          t_op;   /* operation to be performed */
    norns_resource_t    t_src;  /* source resource */
    norns_resource_t    t_dst;  /* destination resource */
} norns_iotask_t;

#if 0 // deprecated
#define NORNS_IOTD_INIT(type, src, dst) \
{ \
    .io_taskid = 0, \
@@ -158,31 +64,7 @@ struct norns_iotd {
    .io_src = src, \
    .io_dst = dst \
}

#define NORNS_INPUT_PATH_INIT(type, path) \
{ \
    .in_type = (type), \
    .__in_location = { \
        .__in_path = path \
    } \
}

#define NORNS_INPUT_BUFFER_INIT(addr, size) \
{ \
    .in_type = NORNS_BACKEND_PROCESS_MEMORY, \
    .__in_location = { \
        .__in_buffer = NORNS_MEMBUFFER_INIT((addr), (size)) \
    } \
}

#define NORNS_OUTPUT_PATH_INIT(type, path) \
{ \
    .out_type = (type), \
    .out_path = path \
}



#endif

/* Task types */
//enum {
@@ -192,10 +74,9 @@ struct norns_iotd {
//    NORNS_REMOTE = 00000020
//};

#define NORNS_COPY      00000000
#define NORNS_MOVE      00000001
#define NORNS_LOCAL     00000010
#define NORNS_REMOTE    00000020

#define NORNS_IOTASK_COPY 0x1
#define NORNS_IOTASK_MOVE 0x2


/* I/O task status descriptor */
@@ -210,32 +91,43 @@ enum {
    NORNS_COMPLETE
};


//void norns_init() __THROW;

//int norns_getconf() __THROW;

/**************************************************************************/
/* Client API                                                             */
/**************************************************************************/

/* Enqueue an asynchronous I/O task */
int norns_transfer(struct norns_iotd* iotdp) __THROW;
/* Initialize an asynchronous I/O task */
void norns_iotask_init(norns_iotask_t* task, norns_op_t operation,
                       norns_resource_t* src, norns_resource_t* dst);

norns_iotask_t NORNS_IOTASK(norns_op_t operation, norns_resource_t src, 
                            norns_resource_t dst);

// XXX deprecated
/* Initialize a resource */
//void norns_resource_init(norns_resource_flags_t flags, norns_resource_t* res, 
//                         void* info);

/* wait for the completion of the task associated to iotdp */
int norns_wait(struct norns_iotd* iotdp) __THROW;
// XXX deprecated
/* Submit an asynchronous I/O task */
// int norns_transfer(struct norns_iotd* iotdp) __THROW;

/* Try to cancel an asynchronous I/O task associated with iotdp */
ssize_t norns_cancel(struct norns_iotd* iotdp) __THROW;
/* Submit an asynchronous I/O task */
norns_error_t norns_submit(norns_iotask_t* task) __THROW;

/* Retrieve return status associated with iotdp */
ssize_t norns_return(struct norns_iotd* iotdp, struct norns_iotst* statp) __THROW;
/* wait for the completion of the task associated to task */
int norns_wait(norns_iotask_t* task) __THROW;

/* Retrieve current status associated with iotdp (if iotdp is NULL, retrieve status for all running tasks) */
ssize_t norns_progress(struct norns_iotd* iotdp, struct norns_iotst* statp) __THROW;
/* Try to cancel an asynchronous I/O task associated with task */
ssize_t norns_cancel(norns_iotask_t* task) __THROW;

/* Retrieve error status associated with iotdp */
int norns_error(struct norns_iotd* iotdp) __THROW;
/* Retrieve return status associated with task */
ssize_t norns_return(norns_iotask_t* task, struct norns_iotst* statp) __THROW;

/* Retrieve current status associated with task (if task is NULL, retrieve status for all running tasks) */
ssize_t norns_progress(norns_iotask_t* task, struct norns_iotst* statp) __THROW;

/* Retrieve error status associated with task */
int norns_error(norns_iotask_t* task) __THROW;

/* Check if the urd daemon is running */
int norns_ping() __THROW;
@@ -243,77 +135,48 @@ int norns_ping() __THROW;

/**************************************************************************/
/* Administrative API                                                     */
/* (only authenticated processes will be able to successfully call these) */
/* (only authenticated processes will be able to successfully use these)  */
/**************************************************************************/

/* Storage backend descriptor */
struct norns_backend {
    const char* b_prefix; /* prefix ID for this backend (e.g. nvm01, tmpfs02, ...) */
    int         b_type;
typedef struct {
    const char* b_nsid;     /* namespace ID for this backend (e.g. nvm01, tmpfs02, ...) */
    int         b_type;     /* backend type */
    const char* b_mount;    /* mount point */
    size_t      b_quota;    /* backend capacity (in megabytes) allocated to the job for writing */
};
} norns_backend_t;

#define NORNS_BACKEND_INIT(prefix, type, mount, quota) \
{ \
    .b_prefix = (prefix), \
    .b_type = (type), \
    .b_mount = (mount), \
    .b_quota = (quota) \
}
norns_backend_t NORNS_BACKEND(const char* nsid, norns_flags_t flags, 
                              const char* mount_point, uint32_t quota);

void norns_backend_init(norns_backend_t* backend, const char* nsid, 
                        norns_flags_t flags, const char* mount_point,
                        uint32_t quota);

#define NORNS_ALLOC(size)       \
({                              \
    size_t __n = (size);        \
    void* __p = malloc(__n);    \
    assert(__p != NULL);        \
    __p;                        \
})

#define NORNS_FREE(p)   \
({                      \
    free(__p;)          \
})

#define NORNS_PLIST_ALLOC(type, size)                               \
({                                                                  \
    size_t __n = (size);                                            \
    void** __plist = (void**) malloc(sizeof(type) * (__n + 1));     \
    memset(__plist, 0, __n + 1);                                    \
    (type*) __plist;                                                \
})

#define NORNS_PLIST_FREE(plist)     \
({                                  \
    free((plist));                  \
})

/* Batch job descriptor */
struct norns_job {
    const char**            jb_hosts;  /* NULL-terminated list of hostnames participating in the job */
    size_t                  jb_nhosts; /* entries in hostname list */
    struct norns_backend**  jb_backends; /* NULL-terminated list of storage backends the job is allowed to use */
    size_t                  jb_nbackends; /* entries in backend list */
};
typedef struct {
    const char**      j_hosts;  /* NULL-terminated list of hostnames participating in the job */
    size_t            j_nhosts; /* entries in hostname list */
    norns_backend_t** j_backends; /* NULL-terminated list of storage backends the job is allowed to use */
    size_t            j_nbackends; /* entries in backend list */
} norns_job_t;

#define NORNS_JOB_INIT(hosts, nhosts, backends, nbackends) \
{ \
    .jb_hosts = (hosts), \
    .jb_nhosts = (nhosts), \
    .jb_backends = (backends), \
    .jb_nbackends = (nbackends) \
}
norns_job_t NORNS_JOB(const char** hosts, size_t nhosts, 
                      norns_backend_t** backends, size_t nbackends);

void norns_job_init(norns_job_t* job, const char** hosts, size_t nhosts, 
                    norns_backend_t** backends, size_t nbackends);

/* Send a command to the daemon (e.g. stop accepting new tasks) */
int norns_command(struct norns_cred* auth);

/* Register a batch job into the system */
int norns_register_job(struct norns_cred* auth, uint32_t jobid, struct norns_job* job);
int norns_register_job(struct norns_cred* auth, uint32_t jobid, norns_job_t* job);

/* Update an existing batch job */
/* XXX: At the moment this invalidates all registered processes for this job */
int norns_update_job(struct norns_cred* auth, uint32_t jobid, struct norns_job* job);
int norns_update_job(struct norns_cred* auth, uint32_t jobid, norns_job_t* job);

/* Remove a batch job from the system */
int norns_unregister_job(struct norns_cred* auth, uint32_t jobid);
@@ -325,10 +188,10 @@ int norns_add_process(struct norns_cred* auth, uint32_t jobid, uid_t uid, gid_t
int norns_remove_process(struct norns_cred* auth, uint32_t jobid, uid_t uid, gid_t gid, pid_t pid);

/* Register a backend in the local norns server */
int norns_register_backend(struct norns_cred* auth, struct norns_backend* backend);
int norns_register_backend(struct norns_cred* auth, norns_backend_t* backend);

/* Update an existing backend in the local norns server */
int norns_register_backend(struct norns_cred* auth, struct norns_backend* backend);
int norns_register_backend(struct norns_cred* auth, norns_backend_t* backend);

/* Unregister a backend from the local norns server */
int norns_unregister_backend(struct norns_cred* auth, const char* prefix);
+5 −4
Original line number Diff line number Diff line
@@ -28,13 +28,14 @@
extern "C" {
#endif

/* Storage resource types */
#define NORNS_BACKEND_LOCAL_NVML        0x10000000
#define NORNS_BACKEND_REMOTE_NVML       0x10000001
/* Storage backend types */
//#define NORNS_BACKEND_LOCAL_NVML        0x10000000
//#define NORNS_BACKEND_REMOTE_NVML       0x10000001
#define NORNS_BACKEND_NVML              0x10000001
#define NORNS_BACKEND_LUSTRE            0x10000002
#define NORNS_BACKEND_PROCESS_MEMORY    0x10000003
#define NORNS_BACKEND_ECHOFS            0x10000004

#define NORNS_BACKEND_POSIX_FILESYSTEM  0x10000005

#ifdef __cplusplus
}
Loading