3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright (c) 2012 by Delphix. All rights reserved.
24 * Copyright (c) 2013 Steven Hartland. All rights reserved.
25 */
26
27 /*
28 * LibZFS_Core (lzc) is intended to replace most functionality in libzfs.
29 * It has the following characteristics:
30 *
31 * - Thread Safe. libzfs_core is accessible concurrently from multiple
32 * threads. This is accomplished primarily by avoiding global data
33 * (e.g. caching). Since it's thread-safe, there is no reason for a
34 * process to have multiple libzfs "instances". Therefore, we store
35 * our few pieces of data (e.g. the file descriptor) in global
36 * variables. The fd is reference-counted so that the libzfs_core
37 * library can be "initialized" multiple times (e.g. by different
38 * consumers within the same process).
39 *
40 * - Committed Interface. The libzfs_core interface will be committed,
41 * therefore consumers can compile against it and be confident that
42 * their code will continue to work on future releases of this code.
43 * Currently, the interface is Evolving (not Committed), but we intend
563 zc.zc_begin_record = drr.drr_u.drr_begin;
564
565 /* zc_cookie is fd to read from */
566 zc.zc_cookie = fd;
567
568 /* zc guid is force flag */
569 zc.zc_guid = force;
570
571 /* zc_cleanup_fd is unused */
572 zc.zc_cleanup_fd = -1;
573
574 error = ioctl(g_fd, ZFS_IOC_RECV, &zc);
575 if (error != 0)
576 error = errno;
577
578 out:
579 if (packed != NULL)
580 fnvlist_pack_free(packed, size);
581 free((void*)(uintptr_t)zc.zc_nvlist_dst);
582 return (error);
583 }
|
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright (c) 2013 by Delphix. All rights reserved.
24 * Copyright (c) 2013 Steven Hartland. All rights reserved.
25 */
26
27 /*
28 * LibZFS_Core (lzc) is intended to replace most functionality in libzfs.
29 * It has the following characteristics:
30 *
31 * - Thread Safe. libzfs_core is accessible concurrently from multiple
32 * threads. This is accomplished primarily by avoiding global data
33 * (e.g. caching). Since it's thread-safe, there is no reason for a
34 * process to have multiple libzfs "instances". Therefore, we store
35 * our few pieces of data (e.g. the file descriptor) in global
36 * variables. The fd is reference-counted so that the libzfs_core
37 * library can be "initialized" multiple times (e.g. by different
38 * consumers within the same process).
39 *
40 * - Committed Interface. The libzfs_core interface will be committed,
41 * therefore consumers can compile against it and be confident that
42 * their code will continue to work on future releases of this code.
43 * Currently, the interface is Evolving (not Committed), but we intend
563 zc.zc_begin_record = drr.drr_u.drr_begin;
564
565 /* zc_cookie is fd to read from */
566 zc.zc_cookie = fd;
567
568 /* zc guid is force flag */
569 zc.zc_guid = force;
570
571 /* zc_cleanup_fd is unused */
572 zc.zc_cleanup_fd = -1;
573
574 error = ioctl(g_fd, ZFS_IOC_RECV, &zc);
575 if (error != 0)
576 error = errno;
577
578 out:
579 if (packed != NULL)
580 fnvlist_pack_free(packed, size);
581 free((void*)(uintptr_t)zc.zc_nvlist_dst);
582 return (error);
583 }
584
585 /*
586 * Roll back this filesystem or volume to its most recent snapshot.
587 * If snapnamebuf is not NULL, it will be filled in with the name
588 * of the most recent snapshot.
589 *
590 * Return 0 on success or an errno on failure.
591 */
592 int
593 lzc_rollback(const char *fsname, char *snapnamebuf, int snapnamelen)
594 {
595 nvlist_t *args;
596 nvlist_t *result;
597 int err;
598
599 args = fnvlist_alloc();
600 err = lzc_ioctl(ZFS_IOC_ROLLBACK, fsname, args, &result);
601 nvlist_free(args);
602 if (err == 0 && snapnamebuf != NULL) {
603 const char *snapname = fnvlist_lookup_string(result, "target");
604 (void) strlcpy(snapnamebuf, snapname, snapnamelen);
605 }
606 return (err);
607 }
|