2 * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
4 * Contact: Krzysztof Dynowski <k.dynowski@samsung.com>
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License
22 * @author Krzysztof Dynowski (k.dynowski@samsung.com)
23 * @brief Vasum old API
32 #include <sys/types.h>
33 #include <sys/mount.h>
35 #include "vasum_list.h"
38 #define API __attribute__((visibility("default")))
52 * @addtogroup CONTEXT vasum context
57 *@brief vasum handle for interact with vasum server process. This is opaque data type.
59 typedef struct vsm_context* vsm_context_h;
62 * @brief Create vsm context
64 * The vsm context is an abstraction of the logical connection between the zone controller and it's clients.
65 * and vsm_context_h object should be finalized when interaction with the vasum server is no longer required.\n
66 * \return An instance of vsm context on success, or NULL
67 * \retval vsm_context_h successful
68 * \retval NULL get vasum context failed.
69 * \par Known issues/bugs:
70 * Only a host process has permission for vsm_create_context();
71 * \pre vsm-zone-svc must be started
72 * \see vsm_cleanup_context()
74 API vsm_context_h vsm_create_context(void);
77 * @brief Cleanup zone control context
79 * vsm_cleanup_context() finalizes vsm context and release all resources allocated to the vsm context.\n
80 * This function should be called if interaction with the zone controller is no longer required.
81 * \param[in] ctx vsm context
82 * \return #VSM_ERROR_NONE on success.
83 * \pre vsm_context_h must be initialized by vsm_create_context()
84 * \post vsm context_h will not be valid after calling this API
85 * \see vsm_create_context()
87 API int vsm_cleanup_context(vsm_context_h ctx);
90 * @brief Get file descriptor associated with event dispatcher of zone control context
92 * The function vsm_get_poll_fd() returns the file descriptor associated with the event dispatcher of vsm context.\n
93 * The file descriptor can be bound to another I/O multiplexing facilities like epoll, select, and poll.
94 * \param[in] ctx vsm context
95 * \return On success, a nonnegative file descriptor is returned. On negative error code is returned.
96 * \retval fd nonnegative integer fd value for getting vasum event and refresh vsm_context_h.
97 * \retval #VSM_ERROR_INVALID invalid vsm_context_h
98 * \pre vsm_context_h must be initialized by vsm_create_context()
99 * \see vsm_create_context()
101 API int vsm_get_poll_fd(vsm_context_h ctx);
104 * @brief Wait for an I/O event on a VSM context
106 * vsm_enter_eventloop() waits for event on the vsm context.\n
108 * The call waits for a maximum time of timout milliseconds. Specifying a timeout of -1 makes vsm_enter_eventloop() wait indefinitely,
109 * while specifying a timeout equal to zero makes vsm_enter_eventloop() to return immediately even if no events are available.
110 * \param[in] ctx vsm context
111 * \param[in] flags Reserved
112 * \param[in] timeout Timeout time (milisecond), -1 is infinite
113 * \return 0 on success, or negative error code.
114 * \pre vsm context must be initialized by vsm_create_context()
115 * \see vsm_create_context(), vsm_get_poll_fd()
117 API int vsm_enter_eventloop(vsm_context_h ctx, int flags, int timeout);
120 * @brief Enumeration for vasum error.
123 VSM_ERROR_NONE, /**< The operation was successful */
124 VSM_ERROR_GENERIC, /**< Non-specific cause */
125 VSM_ERROR_INVALID, /**< Invalid argument */
126 VSM_ERROR_CANCELED, /**< The requested operation was cancelled */
127 VSM_ERROR_ABORTED, /**< Operation aborted */
128 VSM_ERROR_REFUSED, /**< Connection refused */
129 VSM_ERROR_EXIST, /**< Target exists */
130 VSM_ERROR_BUSY, /**< Resource is busy */
131 VSM_ERROR_IO, /**< I/O error*/
132 VSM_ERROR_TIMEOUT, /**< Timer expired */
133 VSM_ERROR_OVERFLOW, /**< Value too large to be stored in data type */
134 VSM_ERROR_OUT_OF_MEMORY, /**< No memory space */
135 VSM_ERROR_OUT_OF_RANGE, /**< Input is out of range */
136 VSM_ERROR_NOT_PERMITTED, /**< Operation not permitted */
137 VSM_ERROR_NOT_IMPLEMENTED, /**< Function is not implemented yet */
138 VSM_ERROR_NOT_SUPPORTED, /**< Operation is not supported */
139 VSM_ERROR_ACCESS_DENIED, /**< Access privilege is not sufficient */
140 VSM_ERROR_NO_OBJECT, /**< Object not found */
141 VSM_ERROR_BAD_STATE, /**< Bad state */
142 VSM_MAX_ERROR = VSM_ERROR_BAD_STATE
146 * @brief Get last vasum error code from vsm_context.
147 * \param[in] ctx vsm context
148 * \return vasum error enum value.
149 * \par Known issues/bugs:
151 * \see vsm_error_string()
153 API vsm_error_e vsm_last_error(vsm_context_h ctx);
156 * @brief Get vasum error string.
158 * return string pointer for vasum error string.
159 * \param[in] error vsm_error_e.
160 * \return string pointer value represent to error code.
161 * \warning Do not free returned pointer.
163 API const char *vsm_error_string(vsm_error_e error);
168 * @addtogroup LIFECYCLE Vasum Lifecycle
173 * @brief vsm_zone_h opaque datatype which is used to represent an instance of zone.
176 typedef struct vsm_zone* vsm_zone_h;
179 * @brief Definition for default zone name.
180 * Default zone is started at boot sequence by systemd.
182 #define VSM_DEFAULT_ZONE "personal"
186 * @brief Create a new persistent zone
188 * vsm_create_zone() triggers zone controller to create new persistent zone.\n\n
189 * The zone controller distinguishes two types of zones: peristent and transient.
190 * Persistent zones exist indefinitely in storage.
191 * While, transient zones are created and started on-the-fly.\n\n
192 * Creating zone requires template.\n
193 * In general, creating a zone involves constructing root file filesystem and
194 * generating configuration files which is used to feature the zone.
195 * Moreover, it often requires downloading tools and applications pages,
196 * which are not available in device.
197 * In that reason, Vasum Framework delegates this work to templates.
198 * \param[in] ctx vsm context
199 * \param[in] zone_name zone name
200 * \param[in] template_name template name to be used for constructing the zone
201 * \param[in] flag Reserved
202 * \return 0 on success, or negative integer error code on error.
203 * \retval #VSM_ERROR_NONE Successful
204 * \retval #VSM_ERROR_INVALID Invalid arguments
205 * \retval #VSM_ERROR_EXIST The same name zone is existed.
206 * \retval #VSM_ERROR_GENERIC Lxc failed to create zone.
207 * \retval #VSM_ERROR_IO Database access failed
209 API int vsm_create_zone(vsm_context_h ctx, const char *zone_name, const char *template_name, int flag);
212 * @brief Destroy persistent zone
214 * The function vsm_destroy_zone() triggers zone controller to destroy persistent zone corresponding to the given name.\n
215 * All data stored in the repository of the zone are also deleted if force argument is set.
216 * Once the zone repository is deleted, it cannot be recovered.
217 * \param[in] ctx vsm context
218 * \param[in] zone_name zone name
219 * \param[in] force forced flags
220 * - 0 : do not destory running zone.
221 * - non-zero : if zone is running, shutdown forcefully, and destroy.
222 * \return 0 on success, or negative integer error code on error.i
223 * \retval #VSM_ERROR_NONE Successful
224 * \retval #VSM_ERROR_BUSY Target zone is running
225 * \retval #VSM_ERROR_NO_OBJECT Target zone does not exist
226 * \retval #VSM_ERROR_GENERIC Lxc failed to destroy zone
227 * \retval #VSM_ERROR_IO Database access failed
229 API int vsm_destroy_zone(vsm_context_h ctx, const char *zone_name, int force);
232 * @brief Start an execution of a persistent zone
234 * The function vsm_start_zone() triggers zone controller to start zone corresponding to the given name.\n
235 * Caller can speficy the type of zones: transient and peristent.
236 * Persistent zones need to be defined before being start up(see vsm_create_zone())
237 * While, transient zones are created and started on-the-fly.
238 * \param[in] ctx vsm context
239 * \param[in] zone_name zone name
240 * \return 0 on success, or negative integer error code on error.
241 * \retval #VSM_ERROR_NONE Successful
242 * \retval #VSM_ERROR_INVALID Invalid argument.
243 * \retval #VSM_ERROR_BUSY Target zone is already running state.
244 * \retval #VSM_ERROR_NO_OBJECT Target zone does not exist
245 * \retval #VSM_ERROR_GENERIC Lxc failed to start zone
247 API int vsm_start_zone(vsm_context_h ctx, const char *zone_name);
250 * @brief Stop an execution of running zone
252 * Send request to stop running zone.\n
253 * \param[in] ctx vsm context
254 * \param[in] zone_name zone name
255 * \param[in] force option to shutdown.
256 * - 0 : send SIGPWR signal to init process of target zone.
257 * - non-zero : terminate all processes in target zone.
258 * \return 0 on success, or negative integer error code on error.
259 * \retval #VSM_ERROR_NONE Successful
260 * \retval #VSM_ERROR_INVALID Invalid argument.
261 * \retval #VSM_ERROR_BAD_STATE Failed to lookup running zone.
262 * \retval #VSM_ERROR_NO_OBJECT Target zone does not exist
263 * \retval #VSM_ERROR_GENERIC Lxc failed to destroy zone
265 API int vsm_shutdown_zone(vsm_context_h ctx, const char *zone_name, int force);
268 * @brief Shutdown zone and prevent starting zone
270 * Prevent starting target zone.
271 * If target zone is running, shutdown the zone first.
272 * \param[in] ctx vsm context
273 * \param[in] zone_name zone name
274 * \return 0 on success, or negative integer error code on error.
275 * \retval #VSM_ERROR_NONE Successful
276 * \retval #VSM_ERROR_NO_OBJECT Target zone does not exist
277 * \retval #VSM_ERROR_GENERIC Locking failed.
279 API int vsm_lock_zone(vsm_context_h ctx, const char *zone_name, int shutdown);
282 * @brief Allow a zone to be launched
284 * Remove lock applied to the zone corresponding to the given name.
285 * \param[in] ctx vsm context
286 * \param[in] zone_name zone name
287 * \return 0 on success, or negative integer error code on error.
288 * \retval #VSM_ERROR_NONE Successful
289 * \retval #VSM_ERROR_GENERIC Unlocking failed.
291 API int vsm_unlock_zone(vsm_context_h ctx, const char *zone_name);
294 * @brief Switch target zone to foreground
296 * Switch target zone to foreground on device.
297 * \param[in] zone vsm_zone_h
298 * \return 0 on success, or negative integer error code on error.
299 * \retval #VSM_ERROR_NONE Successful
300 * \retval #VSM_ERROR_INVALID vsm_zone_h is invalid
302 API int vsm_set_foreground(vsm_zone_h zone);
305 * @brief Get current foreground zone on device
307 * Get foreground zone handle.
308 * \param[in] ctx vsm_context_h
309 * \return 0 on success, or negative integer error code on error.
310 * \retval #VSM_ERROR_NONE Successful
311 * \retval #VSM_ERROR_INVALID vsm_context_h is invalid
313 API vsm_zone_h vsm_get_foreground(vsm_context_h ctx);
317 * @addtogroup ACCESS Vasum Access
322 * @brief Definition for zone states.
323 * This definition shows the available states.
326 VSM_ZONE_STATE_STOPPED, /**< Zone stopped */
327 VSM_ZONE_STATE_STARTING, /**< Zone is prepare for running */
328 VSM_ZONE_STATE_RUNNING, /**< Zone is running on device */
329 VSM_ZONE_STATE_STOPPING, /**< Zone is stopping by request */
330 VSM_ZONE_STATE_ABORTING, /**< Zone is failed to start */
331 VSM_ZONE_STATE_FREEZING, /**< Reserved State */
332 VSM_ZONE_STATE_FROZEN, /**< Reserved State */
333 VSM_ZONE_STATE_THAWED, /**< Reserved State */
334 VSM_ZONE_MAX_STATE = VSM_ZONE_STATE_THAWED
339 * @brief Definition for zone events
342 VSM_ZONE_EVENT_NONE, /**< Zone has no event */
343 VSM_ZONE_EVENT_CREATED, /**< Zone is created */
344 VSM_ZONE_EVENT_DESTROYED, /**< Zone is destroted */
345 VSM_ZONE_EVENT_SWITCHED, /**< Foreground is switched */
346 VSM_ZONE_MAX_EVENT = VSM_ZONE_EVENT_SWITCHED
351 * @brief Definition for zone iteration callback function.
353 typedef void (*vsm_zone_iter_cb)(vsm_zone_h zone, void *user_data);
355 * @brief Definition for zone state changed callback function.
357 typedef int (*vsm_zone_state_changed_cb)(vsm_zone_h zone, vsm_zone_state_t state, void *user_data);
359 * @brief Definition for zone event callback function.
361 typedef int (*vsm_zone_event_cb)(vsm_zone_h zone, vsm_zone_event_t event, void *user_data);
364 * @brief Interate all zone instances which are in running state
366 * This API traverses all zones which are in running state, and callback function will be called on every entry.
367 * \param[in] ctx vsm context
368 * \param[in] callback Function to be executed in iteration, which can be NULL
369 * \param[in] user_data Parameter to be passed to callback function
370 * \return 0 on success, or negative integer error code on error.
371 * \retval #VSM_ERROR_NONE Successful
372 * \retval #VSM_ERROR_OUT_OF_MEMORY Zone handle allocation failed
373 * \retval #VSM_ERROR_GENERIC Zone initialize failed
374 * \remark In case of callback and is NULL,
375 * This API refresh vsm_context which means reloading current running zone to vsm_context again.
377 API int vsm_iterate_zone(vsm_context_h ctx, vsm_zone_iter_cb callback, void *user_data);
380 * @brief Find zone corresponding to the name
381 * The function vsm_lookup_zone_by_name() looks for the zone instance corresponding to the given name.
382 * \param[in] ctx vsm context
383 * \param[in] name zone name
384 * \return Zone instance on success, or NULL on error.
385 * \retval vsm_zone_h Successful
386 * \retval NULL Failed to lookup
387 * \pre vsm_context_h have to bind by vsm_enter_eventloop() or vsm_context_h does not have current zone status.
388 * \see vsm_create_context(), vsm_enter_eventloop()
390 API vsm_zone_h vsm_lookup_zone_by_name(vsm_context_h ctx, const char *name);
393 * @brief Find zone instance associated with the process id
395 * The function vsm_lookup_zone_by_pid() looks for the zone instance associated with the given pid.
396 * \param[in] ctx vsm context
397 * \param[in] pid Process id
398 * \return Zone instance on success, or NULL on error.
399 * \retval vsm_zone_h Successful
400 * \retval NULL Failed to lookup
401 * \pre vsm_context_h have to bind by vsm_enter_eventloop() or vsm_context_h does not have current zone status.
402 * \see vsm_create_context(), vsm_enter_eventloop()
404 API vsm_zone_h vsm_lookup_zone_by_pid(vsm_context_h ctx, pid_t pid);
407 * @brief Register zone status changed callback
409 * Register a callback function for zone status change.
410 * \param[in] ctx vsm context
411 * \param[in] callback Callback function to invoke when zone satte event occurs
412 * \return Callback handle on success, or negative error code on error.
413 * \retval handle nonnegative handle id for callback.
414 * \retval #VSM_ERROR_OUT_OF_MEMORY Callback hanlder allocation failed.
415 * \pre vsm_context_h have to bind by vsm_enter_eventloop() or callback function does not called.
416 * \see vsm_create_context(), vsm_enter_eventloop(), vsm_del_state_changed_callback()
418 API int vsm_add_state_changed_callback(vsm_context_h ctx, vsm_zone_state_changed_cb callback, void *user_data);
421 * @brief Deregister zone status changed callback handler
423 * Remove an event callback from the zone control context.
424 * \param[in] ctx vsm context
425 * \param[in] handle Callback Id to remove
426 * \return 0 on success, or negative integer error code on error.
427 * \retval #VSM_ERROR_NONE Successful
428 * \retval #VSM_ERROR_NO_OBJECT Failed to lookup callback handler
430 API int vsm_del_state_changed_callback(vsm_context_h ctx, int handle);
433 * @brief Register zone event callback
435 * Register a callback function for zone event.
436 * \param[in] ctx vsm context
437 * \param[in] callback callback function to invoke when zone event occurs
438 * \return positive callback handle on success, or negative error code on error.
439 * \retval handle nonnegative handle id for callback.
440 * \retval #VSM_ERROR_OUT_OF_MEMORY Callback hanlder allocation failed.
441 * \pre vsm_context_h have to bind by vsm_enter_eventloop() or callback function does not called.
442 * \see vsm_create_context(), vsm_enter_eventloop(), vsm_del_state_changed_callback()
444 API int vsm_add_event_callback(vsm_context_h ctx, vsm_zone_event_cb callback, void *user_data);
447 * @brief Deregister zone event callback handler
449 * Remove an event callback from the zone control context.
450 * \param[in] ctx vsm context
451 * \param[in] handle callback handle to remove
452 * \return 0 on success, or negative integer error code on error.
453 * \retval #VSM_ERROR_NONE Successful
454 * \retval #VSM_ERROR_NO_OBJECT Failed to lookup callback handler
456 API int vsm_del_event_callback(vsm_context_h ctx, int handle);
459 * @brief Zone attach parameters
460 * Arguments are same as linux system-call execv()
462 typedef struct vsm_attach_command_s {
463 char * exec; /**< Program binary path */
464 char ** argv; /**< An array of argument pointers to null-terminated strings include program path */
465 } vsm_attach_command_s;
468 * @brief Zone attach option
470 typedef struct vsm_attach_options_s {
471 uid_t uid; /**< requested uid*/
472 gid_t gid; /**< requested gid*/
473 int env_num; /**< requested environ count */
474 char **extra_env; /**< requested environ string pointer array. */
475 } vsm_attach_options_s;
478 * @brief default attach options
482 * env = no extra env\n
485 #define VSM_ATTACH_OPT_DEFAULT { (uid_t)0, (gid_t)0, 0, NULL }
488 * @brief Launch a process in a running zone.
490 * Execute specific command inside the zone with given arguments and environment
491 * \param[in] zone_name vsm_zone_h
492 * \param[in] command vsm attach command
493 * \param[in] opt vsm attach options (can be NULL), using VSM_ATTACH_OPT_DEFAULT
494 * \param[out] attached_process process pid
495 * \return On sucess 0, otherwise, a negative integer error code on error
496 * \retval #VSM_ERROR_NONE Successful
497 * \retval #VSM_ERROR_INVALID Invalid arguments
498 * \retval #VSM_ERROR_NO_OBJECT Target zone is not running state
499 * \retval #VSM_ERROR_GENERIC IPC failed
501 API int vsm_attach_zone(vsm_context_h ctx, const char * zone_name, vsm_attach_command_s * command, vsm_attach_options_s * opt, pid_t *attached_process);
504 * @brief Launch a process in a running zone and wait till child process exited.
506 * Execute specific command inside the zone with given arguments and environment
507 * \param[in] zone_name vsm_zone_h
508 * \param[in] command vsm attach command
509 * \param[in] opt vsm attach options (can be NULL), using VSM_ATTACH_OPT_DEFAULT
510 * \return On sucess waitpid exit code or attached process, or a negative error code
511 * \retval #VSM_ERROR_NONE Successful
512 * \retval #VSM_ERROR_INVALID Invalid arguments
513 * \retval #VSM_ERROR_NO_OBJECT Target zone is not running state
514 * \retval #VSM_ERROR_GENERIC IPC failed or waitpid error
516 API int vsm_attach_zone_wait(vsm_context_h ctx, const char * zone_name, vsm_attach_command_s * command, vsm_attach_options_s * opt);
519 * @brief Get name string of zone.
521 * Get name string of zone.
522 * \param[in] zone vsm zone handle
523 * \return a pointer of zone name string on sucess or NULL on fail.
524 * \retval name string value of zone.
525 * \retval NULL vsm_zone_h is invalid.
526 * \warning Do not modify or free returned pointer memroy.
527 * This memory will be cleanup by vsm_cleanup context()
529 API const char * vsm_get_zone_name(vsm_zone_h zone);
532 * @brief Get zone root ablsolute path on host side.
534 * Get rootpath string of zone.
535 * \param[in] zone vsm zone handle
536 * \return a pointer of zone rootpath string on sucess or NULL on fail.
537 * \retval rootpath string value of zone.
538 * \retval NULL vsm_zone_h is invalid.
539 * \warning Do not modify or free returned memroy.
540 * This memory will be cleanup by vsm_cleanup context()
542 API const char * vsm_get_zone_rootpath(vsm_zone_h zone);
545 * @brief Get type of running zone.
547 * Get type string of zone. This value is defined in template file when using vsm_create_zone()
548 * \param[in] zone vsm zone handle
549 * \return a pointer of zone path string on sucess or NULL on fail.
550 * \retval rootpath string value of zone.
551 * \retval NULL vsm_zone_h is invalid.
552 * \see vsm_create_zone()
553 * \warning Do not modify or free returned memroy.
554 * This memory will be cleanup by vsm_cleanup context()
556 API const char * vsm_get_zone_type(vsm_zone_h zone);
559 * @brief Check zone handle, a host or a normal zone by zone handle.
560 * \param[in] zone vsm zone handle
561 * \return positive integer on host case, or 0 on normal zone.
562 * \retval positive target zone is host zone.
563 * \retval NULL target zone is NOT host.
565 API int vsm_is_host_zone(vsm_zone_h zone);
568 * @brief get zone state.
570 * Get zone state value by zone handle.
571 * \param[in] zone vsm zone handle
572 * \return vsm_zone_state_t value, or negative value.
573 * \retval state vsm_zone_state_t value of zone
574 * \retval #VSM_ERROR_INVALID vsm_zone_h is invalid
577 API vsm_zone_state_t vsm_get_zone_state(vsm_zone_h zone);
580 * @brief get zone id by handle.
582 * Get zone id value by zone handle.
583 * \param[in] zone vsm zone handle
584 * \return interger id value of zone or negative error.
585 * \retval id nonnegative interger value.
586 * \retval #VSM_ERROR_INVALID vsm_zone_h is invalid
587 * \remarks id '0' is reserved for host.
589 API int vsm_get_zone_id(vsm_zone_h zone);
592 * @brief Set userdata pointer value in vsm_zone_h.
594 * Get zone id value by zone handle.
595 * \param[in] zone vsm zone handle
596 * \return On success 0, or negative error.
597 * \retval #VSM_ERROR_NONE Successful.
598 * \retval #VSM_ERROR_INVALID vsm_zone_h is invalid
599 * \warning This userdata have to be free before vsm_cleanup_context() or VSM_ZONE_STATE_STOPPED callback handler
601 API int vsm_set_userdata(vsm_zone_h zone, void * userdata);
604 * @brief Set userdata pointer value in vsm_zone_h.
606 * Get zone id value by zone handle.
607 * \param[in] zone vsm zone handle
608 * \return On success pointer of userdata, or NULL pointer
609 * \retval userdata pointer of userdata.
610 * \retval NULL invalid vsm_zone_h.
611 * \remark initial value is pointer of self vsm_zone_h
613 API void * vsm_get_userdata(vsm_zone_h zone);
617 * @brief join current process into zone.
619 * Change self peer credential to target zone
620 * \param[in] zone vsm_zone_h
621 * \return before vsm_zone on success, or NULL on error.
622 * \retval vsm_zone_h before zone handle, If caller process running in host, then host handle returned.
623 * \retval NULL invalid zone handle.
624 * \pre parameter vsm zone must be lookup by vsm lookup APIs
625 * \post After finish target zone procedure, must join again before zone by same API.
626 * \warning This function is not thread-safe. \n
627 * All requests of threads in same process are considered target zone request to other host processes.
629 API vsm_zone_h vsm_join_zone(vsm_zone_h zone);
632 * @brief get canonical file path based on current zone.
634 * get canonical file path based on current zone.
635 * \param[in] input_path requested zone path
636 * \param[out] output_path string pointer for canonicalized output path
637 * \return int positive string length of output_path, or negative error code on error.
638 * \retval #VSM_ERROR_INVALID Invalid arguments.
639 * \retval #VSM_ERROR_GENERIC gethostname() is failed.
640 * \post Out buffer(*output_path) have to be freed by caller after use.
641 * \remarks This API can call inside zone without vsm_context_h
642 * It means this API can call library side for apps.
644 API int vsm_canonicalize_path(const char *input_path, char **output_path);
647 * @brief Check current environment, a host or virtualized zone.
649 * Check current caller process environment.
650 * \return positive integer on running in zone, or 0 on running in host.
651 * \retval NULL Current process running in host.
652 * \remarks This API can call inside zone without vsm_context_h
653 * It means this API can call library side for apps.
655 API int vsm_is_virtualized(void);
658 * @brief Check equivalence between caller and target pid.
660 * Check API caller process and target pid running in same zone.
661 * \retval NULL target process is running in another zone.
662 * \retval 1 target process is running in same zone.
663 * \retval -1 failed to check target process.
664 * \remarks This API can check real zone of target pid.
665 Real zone is not changed by even join API.
667 API int vsm_is_equivalent_zone(vsm_context_h ctx, pid_t pid);
670 * @brief Translate zone pid to host pid.
672 * This API would translate zone namespace pid to host namespace pid.
673 * \param[in] zone the zone of target process
674 * \param[in] pid target process id of zone namespace
675 * \return positive pid or negative error code.
676 * \retval pid translated host pid of zone process.
677 * \retval #VSM_ERROR_NO_OBJECT No such process in a target zone.
678 * \retval #VSM_ERROR_NOT_PERMITTED Permission denied to get target pid info.
679 * \retval #VSM_ERROR_NOT_SUPPORTED Kernel config is not enabled about pid namespace.
680 * \retval #VSM_ERROR_INVALID Arguments is invalid.
681 * \retval #VSM_ERROR_IO Failed to get process info.
682 * \retval #VSM_ERROR_GENERIC Failed to matching zone pid to host pid.
684 API int vsm_get_host_pid(vsm_zone_h zone, pid_t pid);
690 * @addtogroup NETWORK Vasum Network
695 * @brief Types of virtual network interfaces
698 VSM_NETDEV_VETH, /**< Virtual Ethernet(veth), this type device will be attached to host-side network bridge */
699 VSM_NETDEV_PHYS, /**< Physical device */
700 VSM_NETDEV_MACVLAN /**< Mac VLAN, this type isn't implemented yet */
704 VSM_NETDEV_ADDR_IPV4, /**< IPV4 Address family */
705 VSM_NETDEV_ADDR_IPV6 /**< IPV6 Address family */
709 * @brief Network device information
711 typedef struct vsm_netdev *vsm_netdev_h;
714 * @brief Definition for zone network devince iteration callback function.
716 typedef void (*vsm_zone_netdev_iter)(struct vsm_netdev *, void *user_data);
719 * @brief Create a new network device and assisgn it to zone
721 * This function creates net netdev instance and assign it to the given zone.
722 * \param[in] zone Zone
723 * \param[in] type Type of network device to be create
725 * - If type is veth, this will be bridge name to attach.
726 * - If type is phys, this will be ignored.
727 * \param[in] netdev Name of network device to be create
728 * \return Network devce on success, or NULL on error.
729 * \retval vsm_netdev_h New net device handle
730 * \retval NULL Failed to create netdev
731 * \see vsm_create_netdev()
733 * Macvlan is not implemented yet.
735 API vsm_netdev_h vsm_create_netdev(vsm_zone_h zone, vsm_netdev_type_t type, const char *target, const char *netdev);
738 * @brief Removes a network device from zone
740 * This function remove the given netdev instance from the zone control context.
741 * \param[in] netdev network device to be removed
742 * \return 0 on success, or negative integer error code on error.
743 * \retval #VSM_ERROR_NONE Successful
744 * \retval #VSM_ERROR_INVALID Invalid arguments
745 * \retval #VSM_ERROR_GENERIC Failed to interact with vasum server
746 * \see vsm_destroy_netdev()
748 API int vsm_destroy_netdev(vsm_netdev_h netdev);
751 * @brief Iterates network devices found in the zone vsm context and executes callback() on each interface.
753 * vsm_destroy_netdev() scans all network interfaces which are registered in the vsm context, and calls callback() on each entry.
754 * \param[in] zone Zone
755 * \param[in] callback Function to be executed in iteration, which can be NULL
756 * \param[in] user_data Parameter to be delivered to callback function
757 * \return 0 on success, or negative integer error code on error.
758 * \retval #VSM_ERROR_NONE Successful
759 * \retval #VSM_ERROR_INVALID Invalid arguments
760 * \retval #VSM_ERROR_GENERIC Failed to interact with vasum server
761 * \see vsm_create_netdev(), vsm_destroy_netdev()
763 API int vsm_iterate_netdev(vsm_zone_h zone, vsm_zone_netdev_iter callback, void *user_data);
766 * @brief Find a network device corresponding to the name
768 * The function vsm_lookup_netdev_by_name() looks for a network interface.
769 * \param[in] name Network device name to search
770 * \return Network device on success, or NULL on error.
771 * \retval vsm_netdev_h Target net device handle
772 * \retval NULL Failed to lookup netdev
775 API vsm_netdev_h vsm_lookup_netdev_by_name(vsm_zone_h zone, const char *name);
778 * @brief Turn up a network device in the zone
780 * This function turns up the given netdev instance in the zone.
781 * \param[in] netdev network device to be removed
782 * \return 0 on success, or negative integer error code on error.
783 * \retval #VSM_ERROR_NONE Successful
784 * \retval #VSM_ERROR_INVALID Invalid arguments
785 * \retval #VSM_ERROR_GENERIC Failed to interact with vasum server
786 * \see vsm_down_netdev()
788 API int vsm_up_netdev(vsm_netdev_h netdev);
791 * @brief Turn down a network device in the zone
793 * This function turns down the given netdev instance in the zone.
794 * \param[in] netdev network device to be removed
795 * \return 0 on success, or negative integer error code on error.
796 * \retval #VSM_ERROR_NONE Successful
797 * \retval #VSM_ERROR_INVALID Invalid arguments
798 * \retval #VSM_ERROR_GENERIC Failed to interact with vasum server
799 * \see vsm_down_netdev()
801 API int vsm_down_netdev(vsm_netdev_h netdev);
804 * @brief Get ip address from a network device
806 * The function vsm_get_ip_addr_netdev() get ip address from a network interface
807 * \param[in] netdev Network device to get address
808 * \param[in] addr_family Address family
809 * \param[out] addr Buffer to get address from a network device
810 * \param[out] size Size of buffer
811 * \return 0 on success, or negative integer error code on error.
812 * \retval #VSM_ERROR_NONE Successful
813 * \retval #VSM_ERROR_INVALID Invalid arguments
814 * \retval #VSM_ERROR_OVERFLOW Parameter overflow
815 * \retval #VSM_ERROR_GENERIC Failed to interact with vasum server
816 * \see vsm_set_ip_addr_netdev()
818 API int vsm_get_ip_addr_netdev(vsm_netdev_h netdev, vsm_netdev_addr_t addr_family, char *addr, int size);
821 * @brief Set ip address to a network device
823 * The function vsm_set_ip_addr_netdev() set ipv4 address to a network interface
824 * \param[in] netdev Network device to set address
825 * \param[in] addr_family Address family
826 * \param[in] addr IP address string to be set
827 * \param[in] prefix prefix ( ex> 192.168.122.1/24, 24 is prefix )
828 * \return 0 on success, or negative integer error code on error.
829 * \retval #VSM_ERROR_NONE Successful
830 * \retval #VSM_ERROR_INVALID Invalid arguments
831 * \retval #VSM_ERROR_OVERFLOW Parameter overflow
832 * \retval #VSM_ERROR_GENERIC Failed to interact with vasum server
833 * \see vsm_get_ip_addr_netdev()
835 API int vsm_set_ip_addr_netdev(vsm_netdev_h netdev, vsm_netdev_addr_t addr_family, const char *addr, int prefix);
842 * @addtogroup DEVICE Vasum Device
847 * @brief Grant device to zone
849 * Request permission device file node to target zone.
850 * \param[in] zone vsm_zone_h
851 * \param[in] path device node path
852 * \param[in] flags requested permission O_RDWR, O_WRONLY, O_RDONLY
853 * \return 0 on success, or negative integer error code on error.
854 * \retval #VSM_ERROR_NONE Successful
855 * \retval #VSM_ERROR_INVALID Invalid arguments
856 * \retval #VSM_ERROR_NOT_PERMITTED Change cgroup is not permitted
857 * \retval #VSM_ERROR_GENERIC Failed to interact with vasum server
858 * \see vsm_revoke_device()
860 API int vsm_grant_device(vsm_zone_h zone, const char *path, uint32_t flags);
863 * @brief Revoke device from the zone
865 * Revoke device node permissions from target zone.
866 * \param[in] zone vsm_zone_h
867 * \param[in] path device node path
868 * \return 0 on success, or negative integer error code on error.
869 * \retval #VSM_ERROR_NONE Successful
870 * \retval #VSM_ERROR_INVALID Invalid arguments
871 * \retval #VSM_ERROR_NOT_PERMITTED Change cgroup is not permitted
872 * \retval #VSM_ERROR_GENERIC Failed to interact with vasum server
873 * \see vsm_grant_device()
875 API int vsm_revoke_device(vsm_zone_h zone, const char *path);
880 * @addtogroup RESOURCE Vasum Resource
885 * @brief Definition for declare file type.
888 VSM_FSO_TYPE_DIR, /**< Directoy type */
889 VSM_FSO_TYPE_REG, /**< Regular file type */
890 VSM_FSO_TYPE_FIFO, /**< Fifo file type */
891 VSM_FSO_TYPE_SOCK, /**< Socket file type */
892 VSM_FSO_TYPE_DEV, /**< Device node type */
893 VSM_FSO_MAX_TYPE = VSM_FSO_TYPE_DEV
898 * @brief Declare file mode.
900 typedef mode_t vsm_mode_t;
903 * @brief Declare specific file object to every zone.
905 * Declare host file system to every running zone.
906 * In case of host target file exist, create new file in running zone. or create a new file in running zone.
907 * And add hook info in vsm-resource-provier for automatically link host target file to starting zone.
908 * Smack labels are also copied as same as host labels.
909 * \param[in] ctx vsm context
910 * \param[in] ftype Type of file system object
911 * \param[in] path Path for the file system object
912 * \param[in] flags Flasg
913 * \param[in] mode mode
914 * \return zero on success, or negative value on error.
915 * \retval #VSM_ERROR_NONE successful.
916 * \retval #VSM_ERROR_INVALID Invalid file type or path.
917 * \retval #VSM_ERROR_GENERIC Error in vasum server side.
918 * \retval #VSM_ERROR_NO_OBJECT Source file is not exist in host filesystem
920 API int vsm_declare_file(vsm_context_h ctx, vsm_fso_type_t ftype, const char *path, int flags, vsm_mode_t mode);
923 * @brief Declare hardlink to every zone.
925 * Declare hardlink to host file to every running zone.
926 * And add hook info in vsm-resource-provier for automatically link host target file to starting zone.
927 * In general, this function is used to share file host and all running zones.
928 * Smack labels are also copied as same as host labels.
929 * \param[in] ctx vsm context
930 * \param[in] source source
931 * \param[in] target target
932 * \return zero on success, or negative value on error.
933 * \retval #VSM_ERROR_NONE successful
934 * \retval #VSM_ERROR_INVALID Invalid provision type to db.
935 * \retval #VSM_ERROR_GENERIC Error in vasum server side.
936 * \retval #VSM_ERROR_NO_OBJECT Source file is not exist in host filesystem
938 API int vsm_declare_link(vsm_context_h ctx , const char *source, const char *target);
943 Below datatypes will be opaque.
945 typedef struct vsm_context {
946 void * signal_channel;
947 void * manage_method_channel;
948 void * unpriv_method_channel;
950 pthread_rwlock_t lock;
951 struct adt_list listeners;
952 struct vsm_zone *root_zone;
953 struct vsm_zone *foreground_zone;
954 struct adt_list sc_listeners;
955 struct adt_list ev_listeners;
959 typedef struct vsm_zone {
960 struct vsm_zone *parent;
964 vsm_zone_state_t state;
966 pthread_rwlock_t lock;
967 struct adt_list children;
968 struct adt_list devices;
969 struct adt_list netdevs;
971 struct adt_list list;
972 struct vsm_context *ctx;
976 typedef struct vsm_netdev {
977 struct vsm_zone *zone;
979 vsm_netdev_type_t type;
980 struct adt_list list;
984 Below APIs will be removed.
987 typedef int (*vsm_zone_state_cb)(vsm_zone_h zone, vsm_zone_state_t state ,vsm_zone_event_t event, void *user_data);
989 API int vsm_add_state_callback(vsm_context_h ctx, vsm_zone_state_cb callback, void *user_data);
991 API int vsm_del_state_callback(vsm_context_h ctx, int handle);
993 API int vsm_get_zone_terminal(vsm_zone_h zone);
999 #endif /*! __VASUM_H__ */