Commit 60a33956 authored by Alberto Miranda's avatar Alberto Miranda ♨️
Browse files

Split API in 2 libraries: libnorns and libnornsctl

User-level functions are provided by libnorns.so,
which communicates with the daemon through the
norns_api_global_socket. This socket should allow
anyone to read and write from/to it.

Admin-level functions are provided by
libnornsctl.so, which communicates with urd
through the norns_api_control_socket. This socket
should allow only selected processes to read and
write from/to it.
parent 4aaff69b
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -31,10 +31,12 @@ nornsincludedir=$(includedir)/norns

nornsinclude_HEADERS = \
	norns/norns.h \
	norns/nornsctl.h \
	norns/norns_backends.h \
	norns/norns_error.h \
	norns/norns_resources.h \
	norns/norns_types.h

include_HEADERS = \
	norns.h
	norns.h \
	nornsctl.h
+4 −92
Original line number Diff line number Diff line
@@ -45,12 +45,6 @@
extern "C" {
#endif

/* Process credentials */
struct norns_cred {
    // TODO: to be completed, but at least...
    pid_t cr_pid;    /* PID of the process */
    gid_t cr_gid;    /* GID of the process */
};

/* Descriptor for an I/O task */
typedef struct {
@@ -78,19 +72,10 @@ typedef struct {

/* 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_resource_t* src, norns_resource_t* dst) __THROW;

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);

// XXX deprecated
/* Submit an asynchronous I/O task */
// int norns_transfer(struct norns_iotd* iotdp) __THROW;
                            norns_resource_t dst) __THROW;

/* Submit an asynchronous I/O task */
norns_error_t norns_submit(norns_iotask_t* task) __THROW;
@@ -113,81 +98,8 @@ ssize_t norns_return(norns_iotask_t* task, norns_stat_t* stats) __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;


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

/* Storage backend descriptor */
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) for writing data */
} norns_backend_t;

/* Job access rights descriptor */
typedef struct {
    const char* r_nsid;     /* namespace ID */
    size_t      r_quota;    /* job's quota */
} norns_access_rights_t;

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);


/* Batch job descriptor */
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;

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, 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, norns_job_t* job);

/* Remove a batch job from the system */
int norns_unregister_job(struct norns_cred* auth, uint32_t jobid);

/* Add a process to a registered batch job */
int norns_add_process(struct norns_cred* auth, uint32_t jobid, uid_t uid, gid_t gid, pid_t pid);

/* Remove a process from a registered batch job */
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, norns_backend_t* backend);

/* Update an existing backend in the local norns server */
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);


char* norns_strerror(int errnum);
/* Return a string describing the error number */
char* norns_strerror(int errnum) __THROW;

#ifdef __cplusplus
}
+2 −2
Original line number Diff line number Diff line
@@ -26,8 +26,8 @@
 *************************************************************************/


#if !defined(__NORNS_LIB_H__)
#error "Never include <norns_error.h> directly; use <norns.h> instead."
#if !defined(__NORNS_LIB_H__) && !defined(__NORNSCTL_LIB_H__)
#error "Never include <norns_error.h> directly; use <norns.h> or <nornsctl.h> instead."
#endif

#ifndef __NORNS_ERROR_H__
+129 −0
Original line number Diff line number Diff line
/*************************************************************************
 * Copyright (C) 2017-2018 Barcelona Supercomputing Center               *
 *                         Centro Nacional de Supercomputacion           *
 * All rights reserved.                                                  *
 *                                                                       *
 * This file is part of the NORNS Data Scheduler, a service that allows  *
 * other programs to start, track and manage asynchronous transfers of   *
 * data resources transfers requests between different storage backends. *
 *                                                                       *
 * See AUTHORS file in the top level directory for information           *
 * regarding developers and contributors.                                *
 *                                                                       *
 * The NORNS Data Scheduler is free software: you can redistribute it    *
 * and/or modify it under the terms of the GNU Lesser General Public     *
 * License as published by the Free Software Foundation, either          *
 * version 3 of the License, or (at your option) any later version.      *
 *                                                                       *
 * The NORNS Data Scheduler 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  *
 * Lesser General Public License for more details.                       *
 *                                                                       *
 * You should have received a copy of the GNU Lesser General             *
 * Public License along with the NORNS Data Scheduler.  If not, see      *
 * <http://www.gnu.org/licenses/>.                                       *
 *************************************************************************/

#ifndef __NORNSCTL_LIB_H__
#define __NORNSCTL_LIB_H__ 1

#ifndef NORNSCTL_API_VERSION
#define NORNSCTL_API_VERSION 10
#endif

#include <sys/types.h>
#include "norns_types.h"
#include "norns_error.h"

#ifdef __cplusplus
extern "C" {
#endif

/**************************************************************************/
/* Control API                                                            */
/* (only processes with enough permissions to access the control socket   */
/* will be able to successfully use these)                                */
/**************************************************************************/

/* Process credentials */
struct norns_cred {
    // TODO: to be completed, but at least...
    pid_t cr_pid;    /* PID of the process */
    gid_t cr_gid;    /* GID of the process */
};

/* Descriptor for a storage backend */
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) for writing data */
} norns_backend_t;

/* Descriptor for a batch job */
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;

/* Descriptor for a batch job access rights */
typedef struct {
    const char* r_nsid;     /* namespace ID */
    size_t      r_quota;    /* job's quota */
} norns_access_rights_t;

norns_backend_t NORNS_BACKEND(const char* nsid, norns_flags_t flags, 
                              const char* mount_point, uint32_t quota) __THROW;

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

norns_job_t NORNS_JOB(const char** hosts, size_t nhosts, 
                      norns_backend_t** backends, size_t nbackends) __THROW;

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

/* Check if the urd daemon is running */
int norns_ping() __THROW;

/* 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, norns_job_t* job) __THROW;

/* 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, norns_job_t* job) __THROW;

/* Remove a batch job from the system */
int norns_unregister_job(struct norns_cred* auth, uint32_t jobid) __THROW;

/* Add a process to a registered batch job */
int norns_add_process(struct norns_cred* auth, uint32_t jobid, uid_t uid, gid_t gid, pid_t pid) __THROW;

/* Remove a process from a registered batch job */
int norns_remove_process(struct norns_cred* auth, uint32_t jobid, uid_t uid, gid_t gid, pid_t pid) __THROW;

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

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

/* Unregister a backend from the local norns server */
int norns_unregister_backend(struct norns_cred* auth, const char* prefix) __THROW;

/* Return a string describing the error number */
char* norns_strerror(int errnum) __THROW;

#ifdef __cplusplus
}
#endif

#endif /* __NORNSCTL_LIB_H__ */

include/nornsctl.h

0 → 100644
+28 −0
Original line number Diff line number Diff line
/*************************************************************************
 * Copyright (C) 2017-2018 Barcelona Supercomputing Center               *
 *                         Centro Nacional de Supercomputacion           *
 * All rights reserved.                                                  *
 *                                                                       *
 * This file is part of the NORNS Data Scheduler, a service that allows  *
 * other programs to start, track and manage asynchronous transfers of   *
 * data resources transfers requests between different storage backends. *
 *                                                                       *
 * See AUTHORS file in the top level directory for information           *
 * regarding developers and contributors.                                *
 *                                                                       *
 * The NORNS Data Scheduler is free software: you can redistribute it    *
 * and/or modify it under the terms of the GNU Lesser General Public     *
 * License as published by the Free Software Foundation, either          *
 * version 3 of the License, or (at your option) any later version.      *
 *                                                                       *
 * The NORNS Data Scheduler 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  *
 * Lesser General Public License for more details.                       *
 *                                                                       *
 * You should have received a copy of the GNU Lesser General             *
 * Public License along with the NORNS Data Scheduler.  If not, see      *
 * <http://www.gnu.org/licenses/>.                                       *
 *************************************************************************/

#include "norns/nornsctl.h"
Loading