plugin_api.h 3.5 KB
Newer Older
O
overweight 已提交
1 2
/******************************************************************************
 * Copyright (c) Huawei Technologies Co., Ltd. 2018-2019. All rights reserved.
3 4 5 6
 * iSulad licensed under the Mulan PSL v2.
 * You can use this software according to the terms and conditions of the Mulan PSL v2.
 * You may obtain a copy of Mulan PSL v2 at:
 *     http://license.coscl.org.cn/MulanPSL2
O
overweight 已提交
7 8 9
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
 * PURPOSE.
10
 * See the Mulan PSL v2 for more details.
O
overweight 已提交
11 12 13 14 15 16 17 18 19 20 21
 * Author: jingrui
 * Create: 2018-12-01
 * Description: provide plugin definition
 ******************************************************************************/

#ifndef _PLUGIN_H_
#define _PLUGIN_H_ /* _PLUGIN_H_ */

#include <pthread.h>

#include "map.h"
22 23
#include "specs_api.h" /* oci_runtime_spec */
#include "container_api.h" /* container_t */
O
overweight 已提交
24 25 26 27 28 29 30 31 32 33 34

/*
 * returned int should means:
 *      0       success
 *     -1       failed
 * if not or has other values, please add comment to the function prototype.
 *
 * when check return value, if want to ingore err, please reset err=0 and add
 * comment.
 */

35 36 37
#define PLUGIN_INIT_SKIP 0
#define PLUGIN_INIT_WITH_CONTAINER_RUNNING 1
#define PLUGIN_INIT_WITH_CONTAINER_ALL 2
O
overweight 已提交
38

39 40 41 42
#define PLUGIN_EVENT_CONTAINER_PRE_CREATE 1UL
#define PLUGIN_EVENT_CONTAINER_PRE_START (1UL << 1)
#define PLUGIN_EVENT_CONTAINER_POST_STOP (1UL << 2)
#define PLUGIN_EVENT_CONTAINER_POST_REMOVE (1UL << 3)
O
overweight 已提交
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67

typedef struct plugin_manifest {
    uint64_t init_type;
    uint64_t watch_event;
} plugin_manifest_t;

typedef struct plugin {
    pthread_rwlock_t lock;

    const char *name;
    const char *addr;
    plugin_manifest_t *manifest;

    bool activated;
    size_t activated_errcnt;
    char *activated_errmsg;

    uint64_t ref;
} plugin_t;

/*
 * plugin_new() will take initial get. when the plugin should free, one
 * more plugint_put() shall be called.
 */
plugin_t *plugin_new(const char *name, const char *addr);
68 69
void plugin_get(plugin_t *plugin); /* ref++ */
void plugin_put(plugin_t *plugin); /* ref-- */
O
overweight 已提交
70 71 72 73 74 75 76

int plugin_set_activated(plugin_t *plugin, bool activated, const char *errmsg);
int plugin_set_manifest(plugin_t *plugin, const plugin_manifest_t *manifest);
bool plugin_is_watching(plugin_t *plugin, uint64_t pe);

typedef struct plugin_manager {
    pthread_rwlock_t pm_rwlock;
77 78
    map_t *np; /* name:plugin */
    map_t *eps; /* watch_event:plugins */
O
overweight 已提交
79 80 81
} plugin_manager_t;

/*
L
LiuHao 已提交
82
 * init at isulad start, scan and init/sync all plugins
O
overweight 已提交
83 84 85 86
 */
int pm_init(void);
int pm_scan(void);
/*
L
LiuHao 已提交
87
 * destroy at isulad exit
O
overweight 已提交
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
 */
int pm_destroy();
/*
 * init plugin manifest
 */
int pm_activate_plugin(plugin_t *plugin);
int pm_deactivate_plugin(plugin_t *plugin);

int pm_add_plugin(plugin_t *plugin);
int pm_del_plugin(const plugin_t *plugin);

/*
 * make sure get and put called in-pairs.
 * if not, please add comment.
 */
int pm_get_plugin(const char *name, plugin_t **rplugin);
void pm_put_plugin(plugin_t *plugin);
int pm_get_plugins_nolock(uint64_t pe, plugin_t ***rplugins, size_t *count);

int start_plugin_manager(void);
int plugin_event_container_pre_create(const char *cid, oci_runtime_spec *ocic);
int plugin_event_container_pre_start(const container_t *cont);
int plugin_event_container_post_stop(const container_t *cont);
int plugin_event_container_post_remove(const container_t *cont);
int plugin_event_container_post_remove2(const char *cid, const oci_runtime_spec *oci);

#endif /* _PLUGIN_H_ */