lxc_sys2/lxccontainer.rs
1use std::os::raw::{c_char, c_int, c_uint, c_void};
2
3/// Do not edit the rootfs to change the hostname
4///
5/// ---
6/// **version:** 1.0.0
7pub const LXC_CLONE_KEEPNAME: u32 = 1 << 0;
8/// Do not change the MAC address on network interfaces
9///
10/// ---
11/// **version:** 1.0.0
12pub const LXC_CLONE_KEEPMACADDR: u32 = 1 << 1;
13/// Snapshot the original filesystem(s)
14///
15/// ---
16/// **version:** 1.0.0
17pub const LXC_CLONE_SNAPSHOT: u32 = 1 << 2;
18/// Use the same bdev type
19///
20/// ---
21/// **version:** 1.0.0
22pub const LXC_CLONE_KEEPBDEVTYPE: u32 = 1 << 3;
23/// Snapshot only if bdev supports it, else copy
24///
25/// ---
26/// **version:** 1.0.0
27pub const LXC_CLONE_MAYBE_SNAPSHOT: u32 = 1 << 4;
28/// Number of `LXC_CLONE_*` flags
29///
30/// ---
31/// **version:** 1.0.0
32pub const LXC_CLONE_MAXFLAGS: u32 = 1 << 5;
33/// Redirect `stdin` to `/dev/zero` and `stdout` and `stderr` to `/dev/null`
34///
35/// ---
36/// **version:** 1.0.0
37pub const LXC_CREATE_QUIET: u32 = 1 << 0;
38/// Number of `LXC_CREATE*` flags
39///
40/// ---
41/// **version:** 1.0.0
42pub const LXC_CREATE_MAXFLAGS: u32 = 1 << 1;
43
44#[repr(C)]
45#[derive(Debug, Copy, Clone)]
46pub struct bdev_specs {
47 _unused: [u8; 0],
48}
49
50#[repr(C)]
51#[derive(Debug, Copy, Clone)]
52pub struct lxc_lock {
53 _unused: [u8; 0],
54}
55
56/// An LXC container.
57///
58/// ---
59/// **version:** 1.0.0
60#[repr(C)]
61#[derive(Debug, Copy, Clone)]
62pub struct lxc_container {
63 /// Name of container.
64 name: *mut c_char,
65 /// Full path to configuration file
66 configfile: *mut c_char,
67 /// File to store pid.
68 pidfile: *mut c_char,
69 /// Container semaphore lock.
70 slock: *mut lxc_lock,
71 /// Container private lock.
72 privlock: *mut lxc_lock,
73 /// Number of references to this container.
74 ///
75 /// ---
76 /// **note:** protected by privlock.
77 numthreads: c_int,
78 /// Container configuration.
79 lxc_conf: *mut c_void,
80
81 /// Human-readable string representing last error
82 ///
83 /// ---
84 /// **version:** 1.0.0
85 pub error_string: *mut c_char,
86 /// Last error number
87 ///
88 /// ---
89 /// **version:** 1.0.0
90 pub error_num: c_int,
91 /// Whether container wishes to be daemonized
92 ///
93 /// ---
94 /// **version:** 1.0.0
95 pub daemonize: bool,
96 /// Full path to configuration file
97 ///
98 /// ---
99 /// **version:** 1.0.0
100 pub config_path: *mut c_char,
101
102 /// Determine if `/var/lib/lxc/$name/config` exists.
103 ///
104 /// ---
105 /// **Parameters**
106 ///
107 /// **c** Container.
108 ///
109 /// ---
110 /// **Returns**
111 ///
112 /// `true` if container is defined, else `false`.
113 ///
114 /// ---
115 /// **version:** 1.0.0
116 pub is_defined: unsafe extern "C" fn(c: *mut lxc_container) -> bool,
117
118 /// Determine state of container.
119 ///
120 /// ---
121 /// **Parameters**
122 ///
123 /// **c** Container.
124 ///
125 /// ---
126 /// **Returns**
127 ///
128 /// Static upper-case string representing state of container.
129 ///
130 /// ---
131 /// **note:** Returned string must not be freed.
132 ///
133 /// ---
134 /// **version:** 1.0.0
135 pub state: unsafe extern "C" fn(c: *mut lxc_container) -> *const c_char,
136
137 /// Determine if container is running.
138 ///
139 /// ---
140 /// **Parameters**
141 ///
142 /// **c** Container.
143 ///
144 /// ---
145 /// **Returns**
146 ///
147 /// `true` on success, else `false`.
148 ///
149 /// ---
150 /// **version:** 1.0.0
151 pub is_running: unsafe extern "C" fn(c: *mut lxc_container) -> bool,
152
153 /// Freeze running container.
154 ///
155 /// ---
156 /// **Parameters**
157 ///
158 /// **c** Container.
159 /// ---
160 /// **Returns**
161 ///
162 /// `true` on success, else `false`.
163 ///
164 /// ---
165 /// **version:** 1.0.0
166 pub freeze: unsafe extern "C" fn(c: *mut lxc_container) -> bool,
167
168 /// Thaw a frozen container.
169 ///
170 /// ---
171 /// **Parameters**
172 ///
173 /// **c** Container.
174 ///
175 /// ---
176 /// **Returns**
177 ///
178 /// `true` on success, else `false`.
179 ///
180 /// ---
181 /// **version:** 1.0.0
182 pub unfeeze: unsafe extern "C" fn(c: *mut lxc_container) -> bool,
183
184 /// Determine process ID of the containers init process.
185 ///
186 /// ---
187 /// **Parameters**
188 ///
189 /// **c** Container.
190 ///
191 /// ---
192 /// **Returns**
193 ///
194 /// pid of init process as seen from outside the container.
195 ///
196 /// ---
197 /// **version:** 1.0.0
198 pub init_pid: unsafe extern "C" fn(c: *mut lxc_container) -> c_uint,
199
200 /// Load the specified configuration for the container.
201 ///
202 /// ---
203 /// **Parameters**
204 ///
205 /// **c** Container.
206 ///
207 /// **alt_file** Full path to alternate configuration file, or
208 /// `NULL` to use the default configuration file.
209 ///
210 /// ---
211 /// **Returns**
212 ///
213 /// `true` on success, else `false`.
214 ///
215 /// ---
216 /// **version:** 1.0.0
217 pub load_config: unsafe extern "C" fn(
218 c: *mut lxc_container,
219 alt_file: *const c_char,
220 ) -> bool,
221
222 /// Start the container.
223 ///
224 /// ---
225 /// **Parameters**
226 ///
227 /// **c** Container.
228 ///
229 /// **useinit** Use lxcinit rather than `/sbin/init`.
230 ///
231 /// **argv** Array of arguments to pass to init.
232 ///
233 /// ---
234 /// **Returns**
235 ///
236 /// `true` on success, else `false`.
237 ///
238 /// ---
239 /// **version:** 1.0.0
240 pub start: unsafe extern "C" fn(
241 c: *mut lxc_container,
242 useinit: c_int,
243 argv: *const *mut c_char,
244 ),
245
246 /// Start the container (list variant).
247 ///
248 /// ---
249 /// **Parameters**
250 ///
251 /// **c** Container.
252 ///
253 /// **useinit** Use lxcinit rather than `/sbin/init`.
254 ///
255 /// **...** Command-line to pass to init (must end in `NULL`).
256 ///
257 /// ---
258 /// **Returns**
259 ///
260 /// `true` on success, else `false`.
261 ///
262 /// ---
263 /// **note:** Identical to [start](#structfield.start) except that that the
264 /// init arguments are specified via a list rather than an array of
265 /// pointers.
266 ///
267 /// ---
268 /// **version:** 1.0.0
269 pub start1: unsafe extern "C" fn(
270 c: *mut lxc_container,
271 useinit: c_int,
272 ...
273 ) -> bool,
274
275 /// Stop the container.
276 ///
277 /// ---
278 /// **Parameters**
279 ///
280 /// **c** Container.
281 ///
282 /// ---
283 /// **Returns**
284 ///
285 /// `true` on success, else `false`.
286 ///
287 /// ---
288 /// **version:** 1.0.0
289 pub stop: unsafe extern "C" fn(c: *mut lxc_container) -> bool,
290
291 /// Determine if the container wants to run disconnected
292 /// from the terminal.
293 ///
294 /// ---
295 /// **Parameters**
296 ///
297 /// **c** Container.
298 ///
299 /// **state** Value for the daemonize bit (0 or 1).
300 ///
301 /// ---
302 /// **Returns**
303 ///
304 /// `true` if container wants to be daemonised, else `false`.
305 ///
306 /// ---
307 /// **version:** 1.0.0
308 pub want_daemonize:
309 unsafe extern "C" fn(c: *mut lxc_container, state: bool) -> bool,
310
311 /// Determine whether container wishes all file descriptors
312 /// to be closed on startup.
313 ///
314 /// ---
315 /// **Parameters**
316 ///
317 /// **c** Container.
318 ///
319 /// **state** Value for the close_all_fds bit (0 or 1).
320 ///
321 /// ---
322 /// **Returns**
323 ///
324 /// `true` if container wants all file descriptors closed,
325 /// else `false`.
326 ///
327 /// ---
328 /// **version:** 1.0.0
329 pub want_close_all_fds:
330 unsafe extern "C" fn(c: *mut lxc_container, state: bool) -> bool,
331
332 /// Return current config file name.
333 ///
334 /// ---
335 /// **Parameters**
336 ///
337 /// **c** Container.
338 ///
339 /// ---
340 /// **Returns**
341 ///
342 /// config file name, or `NULL` on error.
343 ///
344 /// ---
345 /// **note:** The result is allocated, so the caller must free the result.
346 ///
347 /// ---
348 /// **version:** 1.0.0
349 pub config_file_name:
350 unsafe extern "C" fn(c: *mut lxc_container) -> *mut c_char,
351
352 /// Wait for container to reach a particular state.
353 ///
354 /// ---
355 /// **Parameters**
356 ///
357 /// **c** Container.
358 ///
359 /// **state** State to wait for.
360 ///
361 /// **timeout** Timeout in seconds.
362 ///
363 /// ---
364 /// **Returns**
365 ///
366 /// `true` if state reached within `timeout,` else `false`.
367 ///
368 /// ---
369 /// **note:** A `timeout` of `-1` means wait forever. A `timeout`
370 /// of `0` means do not wait.
371 ///
372 /// ---
373 /// **version:** 1.0.0
374 pub wait: unsafe extern "C" fn(
375 c: *mut lxc_container,
376 state: *const c_char,
377 timeout: c_int,
378 ) -> bool,
379
380 /// Set a key/value configuration option.
381 ///
382 /// ---
383 /// **Parameters**
384 ///
385 /// **c** Container.
386 ///
387 /// **key** Name of option to set.
388 ///
389 /// **value** Value of `name` to set.
390 ///
391 /// ---
392 /// **Returns**
393 ///
394 /// `true` on success, else `false`.
395 ///
396 /// ---
397 /// **version:** 1.0.0
398 pub set_config_item: unsafe extern "C" fn(
399 c: *mut lxc_container,
400 key: *const c_char,
401 value: *const c_char,
402 ) -> bool,
403
404 /// Delete the container.
405 ///
406 /// ---
407 /// **Parameters**
408 ///
409 /// **c** Container.
410 ///
411 /// ---
412 /// **Returns**
413 ///
414 /// `true` on success, else `false`.
415 ///
416 /// ---
417 /// **note:** Container must be stopped and have no dependent snapshots.
418 ///
419 /// ---
420 /// **version:** 1.0.0
421 pub destroy: unsafe extern "C" fn(c: *mut lxc_container) -> bool,
422
423 /// Save configuaration to a file.
424 ///
425 /// ---
426 /// **Parameters**
427 ///
428 /// **c** Container.
429 ///
430 /// **alt_file** Full path to file to save configuration in.
431 ///
432 /// ---
433 /// **Returns**
434 ///
435 /// `true` on success, else `false`.
436 ///
437 /// ---
438 /// **version:** 1.0.0
439 pub save_config: unsafe extern "C" fn(
440 c: *mut lxc_container,
441 alt_file: *const c_char,
442 ) -> bool,
443
444 /// Create a container.
445 ///
446 /// ---
447 /// **Parameters**
448 ///
449 /// **c** Container (with lxcpath, name and a starting configuration set).
450 ///
451 /// **t** Template to execute to instantiate the root filesystem and adjust
452 /// the configuration.
453 ///
454 /// **bdevtype** Backing store type to use (if `NULL,` `dir` will be used).
455 ///
456 /// **specs** Additional parameters for the backing store (for example LVM
457 /// volume group to use).
458 ///
459 /// **flags** `LXC_CREATE_*` options (currently only
460 /// [LXC_CREATE_QUIET](constant.LXC_CREATE_QUIET.html) is supported).
461 ///
462 /// **argv** Arguments to pass to the template, terminated by `NULL`
463 /// (if no arguments are required, just pass `NULL)`.
464 ///
465 /// ---
466 /// **Returns**
467 ///
468 /// `true` on success, else `false`.
469 ///
470 /// ---
471 /// **version:** 1.0.0
472 pub create: unsafe extern "C" fn(
473 c: *mut lxc_container,
474 t: *const c_char,
475 bdevtype: *const c_char,
476 specs: *mut bdev_specs,
477 flags: c_int,
478 argv: *const *mut c_char,
479 ) -> bool,
480
481 /// Create a container (list variant).
482 ///
483 /// ---
484 /// **Parameters**
485 ///
486 /// **c** Container (with lxcpath, name and a starting configuration set).
487 ///
488 /// **t** Template to execute to instantiate the root filesystem and adjust
489 /// the configuration.
490 ///
491 /// **bdevtype** Backing store type to use (if `NULL,` `dir` will be used).
492 ///
493 /// **specs** Additional parameters for the backing store (for example LVM
494 /// volume group to use).
495 ///
496 /// **flags** `LXC_CREATE_*` options (currently only
497 /// [LXC_CREATE_QUIET](constant.LXC_CREATE_QUIET.html) is supported).
498 ///
499 /// **...** Command-line to pass to init (must end in `NULL)`.
500 ///
501 /// ---
502 /// **Returns**
503 ///
504 /// `true` on success, else `false`.
505 ///
506 /// ---
507 /// **note:** Identical to [create](#structfield.create) except that the
508 /// template arguments are specified as a list rather than an array of
509 /// pointers.
510 ///
511 /// ---
512 /// **version:** 1.0.0
513 pub createl: unsafe extern "C" fn(
514 c: *mut lxc_container,
515 t: *const c_char,
516 bdevtype: *const c_char,
517 specs: *mut bdev_specs,
518 flags: c_int,
519 ...
520 ) -> bool,
521
522 /// Rename a container
523 ///
524 /// ---
525 /// **Parameters**
526 ///
527 /// **c** Container.
528 ///
529 /// **newname** New name to be used for the container.
530 ///
531 /// ---
532 /// **Returns**
533 ///
534 /// `true` on success, else `false`.
535 ///
536 /// ---
537 /// **version:** 1.0.0
538 pub rename: unsafe extern "C" fn(
539 c: *mut lxc_container,
540 newname: *const c_char,
541 ) -> bool,
542
543 /// Request the container reboot by sending it `SIGINT`.
544 ///
545 /// ---
546 /// **Parameters**
547 ///
548 /// **c** Container.
549 ///
550 /// ---
551 /// **Returns**
552 /// `true` if reboot request successful, else `false`.
553 ///
554 /// ---
555 /// **version:** 1.0.0
556 pub reboot: unsafe extern "C" fn(c: *mut lxc_container) -> bool,
557
558 /// Request the container shutdown by sending it `SIGPWR`.
559 ///
560 /// ---
561 /// **Parameters**
562 ///
563 /// **c** Container.
564 ///
565 /// **timeout** Seconds to wait before returning false. (-1 to wait forever,
566 /// 0 to avoid waiting).
567 ///
568 /// ---
569 /// **Returns**
570 ///
571 /// `true` if the container was shutdown successfully, else `false`.
572 ///
573 /// ---
574 /// **version:** 1.0.0
575 pub shutdown:
576 unsafe extern "C" fn(c: *mut lxc_container, timeout: c_int) -> bool,
577
578 /// Completely clear the containers in-memory configuration.
579 ///
580 /// ---
581 /// **Parameters**
582 ///
583 /// **c** Container.
584 ///
585 /// ---
586 /// **version:** 1.0.0
587 pub clear_config: unsafe extern "C" fn(c: *mut lxc_container) -> c_void,
588
589 /// Clear a configuration item.
590 ///
591 /// ---
592 /// **Parameters**
593 ///
594 /// **c** Container.
595 ///
596 /// **key** Name of option to clear.
597 ///
598 /// ---
599 /// **Returns**
600 ///
601 /// `true` on success, else `false`.
602 ///
603 /// ---
604 /// **note:** Analog of [set_config_item](#structfield.set_config_item).
605 ///
606 /// ---
607 /// **version:** 1.0.0
608 pub clear_config_item:
609 unsafe extern "C" fn(c: *mut lxc_container, key: *const c_char) -> bool,
610
611 /// Retrieve the value of a config item.
612 ///
613 /// ---
614 /// **Parameters**
615 ///
616 /// **c** Container.
617 ///
618 /// **key** Name of option to get.
619 ///
620 /// **retv** *out* Caller-allocated buffer to write value of `key` into (or
621 /// `NULL` to determine length of value).
622 ///
623 /// **inlen** Length of `retv` (may be zero).
624 ///
625 /// ---
626 /// **Returns**
627 ///
628 /// Length of config items value, or < 0 on error.
629 ///
630 /// ---
631 /// **note:** The caller can (and should) determine how large a buffer to
632 /// allocate for `retv` by initially passing its value as `NULL` and
633 /// considering the return value. This function can then be called again
634 /// passing a newly-allocated suitably-sized buffer.
635 ///
636 /// **note:** If `retv` is NULL, `inlen` is ignored.
637 ///
638 /// **note:** If `inlen` is smaller than required, the value written to
639 /// `retv` will be truncated.
640 ///
641 /// ---
642 /// **version:** 1.0.0
643 pub get_config_item: unsafe extern "C" fn(
644 c: *mut lxc_container,
645 key: *const c_char,
646 retv: *mut c_char,
647 inlen: c_int,
648 ) -> c_int,
649
650 /// Retrieve the value of a config item from running container.
651 ///
652 /// ---
653 /// **Parameters**
654 ///
655 /// **c** Container.
656 ///
657 /// **key** Name of option to get.
658 ///
659 /// ---
660 /// **Returns**
661 ///
662 /// the item or NULL on error.
663 ///
664 /// ---
665 /// **note:** Returned string must be freed by the caller.
666 ///
667 /// ---
668 /// **version:** 1.0.0
669 pub get_running_config_item: unsafe extern "C" fn(
670 c: *mut lxc_container,
671 key: *const c_char,
672 ) -> *mut c_char,
673
674 /// Retrieve a list of config item keys given a key prefix
675 ///
676 /// ---
677 /// **Parameters**
678 ///
679 /// **c** Container.
680 ///
681 /// **key** Name of option to get.
682 ///
683 /// **retv** *out* Caller-allocated buffer to write list of keys to (or
684 /// `NULL` to determine overall length of keys list).
685 ///
686 /// **inlen** Length of `retv` (may be zero).
687 ///
688 /// ---
689 /// **Returns**
690 ///
691 /// Length of keys list, or < 0 on error.
692 ///
693 /// ---
694 /// **note:** The list values written to `retv` are separated by a newline
695 /// character ('\\n').
696 ///
697 /// **note:** The caller can (and should) determine how large a buffer to
698 /// allocate for `retv` by initially passing its value as `NULL` and
699 /// considering the return value. This function can then be called again
700 /// passing a newly-allocated suitably-sized buffer.
701 ///
702 /// **note:** If `retv` is NULL, `inlen` is ignored.
703 ///
704 /// **note:** If `inlen` is smaller than required, the value written to
705 /// `retv` will be truncated.
706 ///
707 /// ---
708 /// **version:** 1.0.0
709 pub get_keys: unsafe extern "C" fn(
710 c: *mut lxc_container,
711 key: *const c_char,
712 retv: *mut c_char,
713 inlen: c_int,
714 ) -> c_int,
715
716 /// Obtain a list of network interfaces.
717 ///
718 /// ---
719 /// **Parameters**
720 ///
721 /// **c** Container.
722 ///
723 /// ---
724 /// **Returns**
725 ///
726 /// Newly-allocated array of network interfaces, or `NULL` on error.
727 ///
728 /// ---
729 /// **note:** The returned array is allocated, so the caller must free it.
730 ///
731 /// **note:** The returned array is terminated with a `NULL` entry.
732 ///
733 /// ---
734 /// **version:** 1.0.0
735 pub get_interfaces:
736 unsafe extern "C" fn(c: *mut lxc_container) -> *mut *mut c_char,
737
738 /// Determine the list of container IP addresses.
739 ///
740 /// ---
741 /// **Parameters**
742 ///
743 /// **c** Container.
744 ///
745 /// **interface** Network interface name to consider.
746 ///
747 /// **family** Network family (for example "inet", "inet6").
748 ///
749 /// **scope** IPv6 scope id (ignored if `family` is not "inet6").
750 ///
751 /// ---
752 /// **Returns**
753 ///
754 /// Newly-allocated array of network interfaces, or `NULL` on error.
755 ///
756 /// ---
757 /// **note:** The returned array is allocated, so the caller must free it.
758 ///
759 /// **note:** The returned array is terminated with a `NULL` entry.
760 ///
761 /// ---
762 /// **version:** 1.0.0
763 pub get_ips: unsafe extern "C" fn(
764 c: *mut lxc_container,
765 interface: *const c_char,
766 family: *const c_char,
767 scope: c_int,
768 ) -> *mut *mut c_char,
769
770 /// Retrieve the specified cgroup subsystem value for the container.
771 ///
772 /// ---
773 /// **Parameters**
774 ///
775 /// **c** Container.
776 ///
777 /// **subsys** cgroup subsystem to retrieve.
778 ///
779 /// **retv** *out* Caller-allocated buffer to write value of `subsys` into
780 /// (or `NULL` to determine length of value).
781 ///
782 /// **inlen** length of `retv` (may be zero).
783 ///
784 /// ---
785 /// **Returns**
786 ///
787 /// Length of `subsys` value, or < 0 on error.
788 ///
789 /// ---
790 /// **note:** If `retv` is `NULL,` `inlen` is ignored.
791 ///
792 /// **note:** If `inlen` is smaller than required, the value written to
793 /// `retv` will be truncated.
794 ///
795 /// ---
796 /// **version:** 1.0.0
797 pub get_cgroup_item: unsafe extern "C" fn(
798 c: *mut lxc_container,
799 subsys: *const c_char,
800 retv: *mut c_char,
801 inlen: c_int,
802 ) -> c_int,
803
804 /// Set the specified cgroup subsystem value for the container.
805 ///
806 /// ---
807 /// **Parameters**
808 ///
809 /// **c** Container.
810 ///
811 /// **subsys** cgroup subsystem to consider.
812 ///
813 /// **value** Value to set for `subsys`.
814 ///
815 /// ---
816 /// **Returns**
817 ///
818 /// `true` on success, else `false`.
819 ///
820 /// ---
821 /// **version:** 1.0.0
822 pub set_cgroup_item: unsafe extern "C" fn(
823 c: *mut lxc_container,
824 subsys: *const c_char,
825 value: *const c_char,
826 ) -> bool,
827
828 /// Determine full path to the containers configuration file.
829 /// Each container can have a custom configuration path. However
830 /// by default it will be set to either the `LXCPATH` configure
831 /// variable, or the lxcpath value in the `LXC_GLOBAL_CONF` configuration
832 /// file (i.e. `/etc/lxc/lxc`.conf).
833 /// The value for a specific container can be changed using
834 /// [set_config_path](#structfield.set_config_path). There is no other way
835 /// to specify this in general at the moment.
836 ///
837 /// ---
838 /// **Parameters**
839 ///
840 /// **c** Container.
841 ///
842 /// ---
843 /// **Returns**
844 ///
845 /// Static string representing full path to configuration file.
846 ///
847 /// ---
848 /// **note:** Returned string must not be freed.
849 ///
850 /// ---
851 /// **version:** 1.0.0
852 pub get_config_path:
853 unsafe extern "C" fn(c: *mut lxc_container) -> *const c_char,
854
855 /// Set the full path to the containers configuration file.
856 ///
857 /// ---
858 /// **Parameters**
859 ///
860 /// **c** Container.
861 ///
862 /// **path** Full path to configuration file.
863 ///
864 /// ---
865 /// **Returns**
866 ///
867 /// `true` on success, else `false`.
868 ///
869 /// ---
870 /// **version:** 1.0.0
871 pub set_config_path: unsafe extern "C" fn(
872 c: *mut lxc_container,
873 path: *const c_char,
874 ) -> bool,
875
876 /// Copy a stopped container.
877 ///
878 /// ---
879 /// **Parameters**
880 ///
881 /// **c** Original container.
882 ///
883 /// **newname** New name for the container. If `NULL,` the same name is
884 /// used and a new lxcpath MUST be specified.
885 ///
886 /// **lxcpath** lxcpath in which to create the new container. If `NULL,`
887 /// the original container's lxcpath will be used.
888 ///
889 /// **flags** Additional `LXC_CLONE*` flags to change the cloning behaviour:
890 /// - [LXC_CLONE_KEEPNAME](constant.LXC_CLONE_KEEPNAME.html)
891 /// - [LXC_CLONE_KEEPMACADDR](constant.LXC_CLONE_KEEPMACADDR.html)
892 /// - [LXC_CLONE_SNAPSHOT](constant.LXC_CLONE_SNAPSHOT.html)
893 ///
894 /// **bdevtype** Optionally force the cloned bdevtype to a specified plugin.
895 /// By default the original is used (subject to snapshot requirements).
896 ///
897 /// **bdevdata** Information about how to create the new storage (i.e.
898 /// fstype and fsdata).
899 ///
900 /// **newsize** In case of a block device backing store, an optional size.
901 /// If `0,` the original backing store's size will be used if possible. Note
902 /// this only applies to the rootfs. For any other filesystems, the original
903 /// size will be duplicated.
904 ///
905 /// **hookargs** Additional arguments to pass to the clone hook script.
906 ///
907 /// ---
908 /// **Returns**
909 ///
910 /// Newly-allocated copy of container `c,` or `NULL` on error.
911 ///
912 /// ---
913 /// **note:** If devtype was not specified, and `flags` contains
914 /// [LXC_CLONE_SNAPSHOT](constant.LXC_CLONE_SNAPSHOT.html) then use the
915 /// native `bdevtype` if possible, else use an overlayfs.
916 ///
917 /// ---
918 /// **version:** 1.0.0
919 pub clone: unsafe extern "C" fn(
920 c: *mut lxc_container,
921 newname: *const c_char,
922 lxcpath: *const c_char,
923 flags: c_int,
924 bdevtype: *const c_char,
925 bdevdata: *const c_char,
926 newsize: u64,
927 hookargs: *mut *mut c_char,
928 ) -> *mut lxc_container,
929
930 /// Allocate a console tty for the container.
931 ///
932 /// ---
933 /// **Parameters**
934 ///
935 /// **c** Container.
936 ///
937 /// **ttynum** *in,out* Terminal number to attempt to allocate, or `-1` to
938 /// allocate the first available tty.
939 ///
940 /// **masterfd** *out* File descriptor refering to the master side of the
941 /// pty.
942 ///
943 /// ---
944 /// **Returns**
945 ///
946 /// tty file descriptor number on success, or `-1` on failure.
947 ///
948 /// ---
949 /// **note:** On successful return, `ttynum` will contain the tty number
950 /// that was allocated.
951 ///
952 /// **note:** The returned file descriptor is used to keep the tty
953 /// allocated. The caller should call close(2) on the returned file
954 /// descriptor when no longer required so that it may be allocated
955 /// by another caller.
956 ///
957 /// ---
958 /// **version:** 1.0.0
959 pub console_getfd: unsafe extern "C" fn(
960 c: *mut lxc_container,
961 ttynum: *mut c_int,
962 masterfd: *mut c_int,
963 ) -> c_int,
964
965 /// Allocate and run a console tty.
966 ///
967 /// ---
968 /// **Parameters**
969 ///
970 /// **c** Container.
971 ///
972 /// **ttynum** Terminal number to attempt to allocate, `-1` to
973 /// allocate the first available tty or `0` to allocate the
974 /// console.
975 ///
976 /// **stdinfd** File descriptor to read input from.
977 ///
978 /// **stdoutfd** File descriptor to write output to.
979 ///
980 /// **stderrfd** File descriptor to write error output to.
981 ///
982 /// **escape** The escape character (1 == 'a', 2 == 'b', ...).
983 ///
984 /// ---
985 /// **Returns**
986 ///
987 /// `0` on success, `-1` on failure.
988 ///
989 /// ---
990 /// **note:** This function will not return until the console has been
991 /// exited by the user.
992 ///
993 /// ---
994 /// **version:** 1.0.0
995 pub console: unsafe extern "C" fn(
996 c: *mut lxc_container,
997 ttynum: c_int,
998 stdinfd: c_int,
999 stdoutfd: c_int,
1000 stderrfd: c_int,
1001 escape: c_int,
1002 ) -> c_int,
1003
1004 /// Create a sub-process attached to a container and run a function inside
1005 /// it.
1006 ///
1007 /// ---
1008 /// **Parameters**
1009 ///
1010 /// **c** Container.
1011 ///
1012 /// **exec_function** Function to run.
1013 ///
1014 /// **exec_payload** Data to pass to `exec_function`.
1015 ///
1016 /// **options** See
1017 /// [lxc_attach_options_t](struct.lxc_attach_options_t.html).
1018 ///
1019 /// **attached_process** *out* Process ID of process running inside
1020 /// container `c` that is running `exec_function`.
1021 ///
1022 /// ---
1023 /// **Returns**
1024 ///
1025 /// `0` on success, `-1` on error.
1026 ///
1027 /// ---
1028 /// **version:** 1.0.0
1029 pub attach: unsafe extern "C" fn(
1030 c: *mut lxc_container,
1031 exec_function: crate::attach_options::lxc_attach_exec_t,
1032 exec_payload: *mut c_void,
1033 options: crate::attach_options::lxc_attach_options_t,
1034 attached_process: c_uint,
1035 ) -> c_int,
1036
1037 /// Run a program inside a container and wait for it to exit.
1038 ///
1039 /// ---
1040 /// **Parameters**
1041 ///
1042 /// **c** Container.
1043 ///
1044 /// **options** See
1045 /// [lxc_attach_options_t](struct.lxc_attach_options_t.html).
1046 ///
1047 /// **program** Full path inside container of program to run.
1048 ///
1049 /// **argv** Array of arguments to pass to `program`.
1050 ///
1051 /// ---
1052 /// **Returns**
1053 ///
1054 /// `waitpid(2)` status of exited process that ran `program,` or `-1` on
1055 /// error.
1056 ///
1057 /// ---
1058 /// **version:** 1.0.0
1059 pub attach_run_wait: unsafe extern "C" fn(
1060 c: *mut lxc_container,
1061 options: crate::attach_options::lxc_attach_options_t,
1062 program: *const c_char,
1063 argv: *const *const c_char,
1064 ) -> c_int,
1065
1066 /// Run a program inside a container and wait for it to exit (list variant).
1067 ///
1068 /// ---
1069 /// **Parameters**
1070 ///
1071 /// **c** Container.
1072 ///
1073 /// **options** See
1074 /// [lxc_attach_options_t](struct.lxc_attach_options_t.html).
1075 ///
1076 /// **program** Full path inside container of program to run.
1077 ///
1078 /// **...** Command-line to pass to `program` (must end in `NULL)`.
1079 ///
1080 /// ---
1081 /// **Returns**
1082 ///
1083 /// `waitpid(2)` status of exited process that ran `program,` or `-1` on
1084 /// error.
1085 ///
1086 /// ---
1087 /// **version:** 1.0.0
1088 pub attach_run_wait1: unsafe extern "C" fn(
1089 c: *mut lxc_container,
1090 options: crate::attach_options::lxc_attach_options_t,
1091 program: *const c_char,
1092 ...
1093 ) -> c_int,
1094
1095 /// Create a container snapshot.
1096 ///
1097 /// Assuming default paths, snapshots will be created as
1098 /// `/var/lib/lxc/<c>/snaps/snap<n>` where `<c>` represents the container
1099 /// name and `<n>` represents the zero-based snapshot number.
1100 ///
1101 /// ---
1102 /// **Parameters**
1103 ///
1104 /// **c** Container.
1105 ///
1106 /// **commentfile** Full path to file containing a description of the
1107 /// snapshot.
1108 ///
1109 /// ---
1110 /// **Returns**
1111 ///
1112 /// -1 on error, or zero-based snapshot number.
1113 ///
1114 /// ---
1115 /// **note:** `commentfile` may be `NULL` but this is discouraged.
1116 ///
1117 /// ---
1118 /// **version:** 1.0.0
1119 pub snapshot: unsafe extern "C" fn(
1120 c: *mut lxc_container,
1121 commentfile: *const c_char,
1122 ) -> c_int,
1123
1124 /// Obtain a list of container snapshots.
1125 ///
1126 /// ---
1127 /// **Parameters**
1128 ///
1129 /// **c** Container.
1130 ///
1131 /// **snapshots** Dynamically-allocated Array of lxc_snapshot's.
1132 ///
1133 /// ---
1134 /// **Returns**
1135 ///
1136 /// Number of snapshots.
1137 ///
1138 /// ---
1139 /// **note:** The array returned in `snapshots` is allocated, so the caller
1140 /// must free it.
1141 ///
1142 /// **note:** To free an individual snapshot as returned in \p
1143 /// snapshots, call the snapshots `free` function (see
1144 /// `src/tests/snapshot.c` for an example).
1145 ///
1146 /// ---
1147 /// **version:** 1.0.0
1148 pub snapshot_list: unsafe extern "C" fn(
1149 c: *mut lxc_container,
1150 snapshots: *mut *mut lxc_snapshot,
1151 ) -> c_int,
1152
1153 /// Create a new container based on a snapshot.
1154 ///
1155 /// The restored container will be a copy (not snapshot) of the snapshot,
1156 /// and restored in the lxcpath of the original container.
1157 ///
1158 /// ---
1159 /// **Parameters**
1160 ///
1161 /// **c** Container.
1162 ///
1163 /// **snapname** Name of snapshot.
1164 ///
1165 /// **newname** Name to be used for the restored snapshot.
1166 ///
1167 /// ---
1168 /// **Returns**
1169 ///
1170 /// `true` on success, else `false`.
1171 ///
1172 /// ---
1173 /// **warning:** If `newname` is the same as the current container
1174 /// name, the container will be destroyed. However, this will
1175 /// fail if the snapshot is overlay-based, since the snapshots
1176 /// will pin the original container.
1177 ///
1178 /// **note:** As an example, if the container exists as `/var/lib/lxc/c1,`
1179 /// snapname might be `'snap0'` (representing `/var/lib/lxcsnaps/c1/snap0)`.
1180 /// If `newname` is `c2,` then `snap0` will be copied to `/var/lib/lxc/c2`.
1181 ///
1182 /// ---
1183 /// **version:** 1.0.0
1184 pub snapshot_restore: unsafe extern "C" fn(
1185 c: *mut lxc_container,
1186 snapname: *const c_char,
1187 newname: *const c_char,
1188 ) -> bool,
1189
1190 /// Destroy the specified snapshot.
1191 ///
1192 /// ---
1193 /// **Parameters**
1194 ///
1195 /// **c** Container.
1196 ///
1197 /// **snapname** Name of snapshot.
1198 ///
1199 /// ---
1200 /// **Returns**
1201 ///
1202 /// `true` on success, else `false`.
1203 ///
1204 /// ---
1205 /// **version:** 1.0.0
1206 pub snapshot_destroy: unsafe extern "C" fn(
1207 c: *mut lxc_container,
1208 snapname: *const c_char,
1209 ) -> bool,
1210
1211 /// Determine if the caller may control the container.
1212 ///
1213 /// ---
1214 /// **Parameters**
1215 ///
1216 /// **c** Container.
1217 ///
1218 /// ---
1219 /// **Returns**
1220 ///
1221 /// `false` if there is a control socket for the container monitor and the
1222 /// caller may not access it, otherwise returns `true`.
1223 ///
1224 /// ---
1225 /// **version:** 1.0.0
1226 pub may_control: unsafe extern "C" fn(c: *mut lxc_container) -> bool,
1227
1228 /// Add specified device to the container.
1229 ///
1230 /// ---
1231 /// **Parameters**
1232 ///
1233 /// **c** Container.
1234 ///
1235 /// **src_path** Full path of the device.
1236 ///
1237 /// **dest_path** Alternate path in the container (or `NULL` to use
1238 /// `src_path)`.
1239 ///
1240 /// ---
1241 /// **Returns**
1242 /// `true` on success, else `false`.
1243 ///
1244 /// ---
1245 /// **version:** 1.0.0
1246 pub add_device_node: unsafe extern "C" fn(
1247 c: *mut lxc_container,
1248 src_path: *const c_char,
1249 dest_path: *const c_char,
1250 ) -> bool,
1251
1252 /// Remove specified device from the container.
1253 ///
1254 /// ---
1255 /// **Parameters**
1256 ///
1257 /// **c** Container.
1258 ///
1259 /// **src_path** Full path of the device.
1260 ///
1261 /// **dest_path** Alternate path in the container (or `NULL` to use
1262 /// `src_path)`.
1263 ///
1264 /// ---
1265 /// **Returns**
1266 /// `true` on success, else `false`.
1267 ///
1268 /// ---
1269 /// **version:** 1.0.0
1270 pub remove_device_node: unsafe extern "C" fn(
1271 c: *mut lxc_container,
1272 src_path: *const c_char,
1273 dest_path: *const c_char,
1274 ) -> bool,
1275}
1276
1277/// An LXC container snapshot.
1278///
1279/// ---
1280/// **version:** 1.0.0
1281#[repr(C)]
1282#[derive(Debug, Copy, Clone)]
1283pub struct lxc_snapshot {
1284 /// Name of snapshot
1285 ///
1286 /// ---
1287 /// **version:** 1.0.0
1288 pub name: *mut c_char,
1289 /// Full path to snapshots comment file (may be `NULL)`
1290 ///
1291 /// ---
1292 /// **version:** 1.0.0
1293 pub comment_pathname: *mut c_char,
1294 /// Time snapshot was created
1295 ///
1296 /// ---
1297 /// **version:** 1.0.0
1298 pub timestamp: *mut c_char,
1299 /// Full path to LXCPATH for snapshot
1300 ///
1301 /// ---
1302 /// **version:** 1.0.0
1303 pub lxcpath: *mut c_char,
1304
1305 /// De-allocate the snapshot.
1306 ///
1307 /// ---
1308 /// **Parameters**
1309 ///
1310 /// **s** Snapshot.
1311 ///
1312 /// ---
1313 /// **version:** 1.0.0
1314 pub free: unsafe extern "C" fn(s: *mut lxc_snapshot) -> c_void,
1315}
1316
1317extern "C" {
1318 /// Create a new container.
1319 ///
1320 /// ---
1321 /// **Parameters**
1322 ///
1323 /// **name** Name to use for container.
1324 ///
1325 /// **configpath** Full path to configuration file to use.
1326 ///
1327 /// ---
1328 /// **Returns**
1329 ///
1330 /// Newly-allocated container, or `NULL` on error.
1331 ///
1332 /// ---
1333 /// **version:** 1.0.0
1334 pub fn lxc_container_new(
1335 name: *const c_char,
1336 configpath: *const c_char,
1337 ) -> *mut lxc_container;
1338
1339 /// Add a reference to the specified container.
1340 ///
1341 /// ---
1342 /// **Parameters**
1343 ///
1344 /// **c** Container.
1345 ///
1346 /// ---
1347 /// **Returns**
1348 ///
1349 /// `true` on success, `false` on error.
1350 ///
1351 /// ---
1352 /// **version:** 1.0.0
1353 pub fn lxc_container_get(lxc_container: *mut lxc_container) -> c_int;
1354
1355 /// Drop a reference to the specified container.
1356 ///
1357 /// ---
1358 /// **Parameters**
1359 ///
1360 /// **c** Container.
1361 ///
1362 /// ---
1363 /// **Returns**
1364 ///
1365 /// `0` on success, `1` if reference was successfully dropped and container
1366 /// has been freed, and `-1` on error.
1367 ///
1368 /// ---
1369 /// **warning:** If `1` is returned, `c` is no longer valid.
1370 ///
1371 /// ---
1372 /// **version:** 1.0.0
1373 pub fn lxc_container_put(lxc_container: *mut lxc_container) -> c_int;
1374
1375 /// Obtain a list of all container states.
1376 ///
1377 /// ---
1378 /// **Parameters**
1379 ///
1380 /// **states** *out* states Caller-allocated array to hold all states
1381 /// (may be `NULL)`.
1382 ///
1383 /// ---
1384 /// **Returns**
1385 ///
1386 /// Number of container states.
1387 ///
1388 /// ---
1389 /// **note:** Passing `NULL` for `states` allows the caller to first
1390 /// calculate how many states there are before calling the function again,
1391 /// the second time providing a suitably-sized array to store the static
1392 /// string pointers in.
1393 ///
1394 /// **note:** The `states` array should be freed by the caller, but not the
1395 /// strings the elements point to.
1396 ///
1397 /// ---
1398 /// **version:** 1.0.0
1399 pub fn lxc_get_wait_states(states: *mut *const c_char) -> c_int;
1400
1401 /// Get the value for a global config key
1402 ///
1403 /// ---
1404 /// **Parameters**
1405 ///
1406 /// **key** The name of the config key
1407 ///
1408 /// ---
1409 /// **Returns**
1410 ///
1411 /// String representing the current value for the key.
1412 ///
1413 /// ---
1414 /// **version:** 1.0.0
1415 pub fn lxc_get_global_config_item(key: *const c_char) -> *const c_char;
1416
1417 /// Determine version of LXC.
1418 ///
1419 /// ---
1420 /// **Returns**
1421 ///
1422 /// Static string representing version of LXC in use.
1423 ///
1424 /// ---
1425 /// **note:** Returned string must not be freed.
1426 ///
1427 /// ---
1428 /// **version:** 1.0.0
1429 pub fn lxc_get_version() -> *const c_char;
1430
1431 /// Get a list of defined containers in a lxcpath.
1432 ///
1433 /// ---
1434 /// **Parameters**
1435 ///
1436 /// **lxcpath** lxcpath under which to look.
1437 ///
1438 /// **names** If not `NULL,` then a list of container names will be returned
1439 /// here.
1440 ///
1441 /// **cret** If not `NULL,` then a list of lxc_containers will be returned
1442 /// here.
1443 ///
1444 /// ---
1445 /// **Returns**
1446 ///
1447 /// Number of containers found, or `-1` on error.
1448 ///
1449 /// ---
1450 /// **note:** Values returned in `cret` are sorted by container name.
1451 ///
1452 /// ---
1453 /// **version:** 1.0.0
1454 pub fn list_defined_containers(
1455 lxcpath: *const c_char,
1456 names: *mut *mut *mut c_char,
1457 cret: *mut *mut *mut lxc_container,
1458 ) -> *const c_int;
1459
1460 /// Get a list of active containers for a given lxcpath.
1461 ///
1462 /// ---
1463 /// **Parameters**
1464 ///
1465 /// **lxcpath** Full `LXCPATH` path to consider.
1466 ///
1467 /// **names** *out* Dynamically-allocated array of container names.
1468 ///
1469 /// **cret** *out* Dynamically-allocated list of containers.
1470 ///
1471 /// ---
1472 /// **Returns**
1473 /// Number of containers found, or -1 on error.
1474 ///
1475 /// ---
1476 /// **note:** Some of the containers may not be "defined".
1477 ///
1478 /// **note:** Values returned in `cret` are sorted by container name.
1479 ///
1480 /// **note:** `names` and `cret` may both (or either) be specified as
1481 /// `NULL`.
1482 ///
1483 /// **note:** `names` and `cret` must be freed by the caller.
1484 ///
1485 /// ---
1486 /// **version:** 1.0.0
1487 pub fn list_active_containers(
1488 lxcpath: *const c_char,
1489 names: *mut *mut *mut c_char,
1490 cret: *mut *mut *mut lxc_container,
1491 ) -> *const c_int;
1492
1493 /// Get a complete list of all containers for a given lxcpath.
1494 ///
1495 /// ---
1496 /// **Parameters**
1497 ///
1498 /// **lxcpath** Full `LXCPATH` path to consider.
1499 ///
1500 /// **names** *out* Dynamically-allocated array of container names.
1501 ///
1502 /// **cret** *out* Dynamically-allocated list of containers.
1503 ///
1504 /// ---
1505 /// **Returns**
1506 /// Number of containers found, or -1 on error.
1507 ///
1508 /// ---
1509 /// **note:** Some of the containers may not be "defined".
1510 ///
1511 /// **note:** Values returned in `cret` are sorted by container name.
1512 ///
1513 /// **note:** `names` and `cret` may both (or either) be specified as
1514 /// `NULL`.
1515 ///
1516 /// **note:** `names` and `cret` must be freed by the caller.
1517 ///
1518 /// ---
1519 /// **version:** 1.0.0
1520 pub fn list_all_containers(
1521 lxcpath: *const c_char,
1522 names: *mut *mut *mut c_char,
1523 cret: *mut *mut *mut lxc_container,
1524 ) -> *const c_int;
1525}