be.c (3f4e6c966c306cb9f983f8d23b658728156ee30e) be.c (920abf4df24e6f654af3698d28c58e481bcca6c3)
1/*
2 * be.c
3 *
4 * Copyright (c) 2017 Kyle J. Kneitinger <kyle@kneit.in>
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions

--- 167 unchanged lines hidden (view full) ---

176 */
177void
178be_nicenum(uint64_t num, char *buf, size_t buflen)
179{
180
181 zfs_nicenum(num, buf, buflen);
182}
183
1/*
2 * be.c
3 *
4 * Copyright (c) 2017 Kyle J. Kneitinger <kyle@kneit.in>
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions

--- 167 unchanged lines hidden (view full) ---

176 */
177void
178be_nicenum(uint64_t num, char *buf, size_t buflen)
179{
180
181 zfs_nicenum(num, buf, buflen);
182}
183
184static int
185be_destroy_cb(zfs_handle_t *zfs_hdl, void *data)
186{
187 int err;
188
189 if ((err = zfs_iter_children(zfs_hdl, be_destroy_cb, data)) != 0)
190 return (err);
191 if ((err = zfs_destroy(zfs_hdl, false)) != 0)
192 return (err);
193 return (0);
194}
195
184/*
185 * Destroy the boot environment or snapshot specified by the name
186 * parameter. Options are or'd together with the possible values:
187 * BE_DESTROY_FORCE : forces operation on mounted datasets
196/*
197 * Destroy the boot environment or snapshot specified by the name
198 * parameter. Options are or'd together with the possible values:
199 * BE_DESTROY_FORCE : forces operation on mounted datasets
188 * TODO: Test destroying a non active but mounted be
189 */
190int
191be_destroy(libbe_handle_t *lbh, char *name, int options)
192{
193 zfs_handle_t *fs;
194 char path[BE_MAXPATHLEN];
195 char *p;
196 int err, force, mounted;

--- 26 unchanged lines hidden (view full) ---

223 /* Check if mounted, unmount if force is specified */
224 if ((mounted = zfs_is_mounted(fs, NULL)) != 0) {
225 if (force)
226 zfs_unmount(fs, NULL, 0);
227 else
228 return (set_error(lbh, BE_ERR_DESTROYMNT));
229 }
230
200 */
201int
202be_destroy(libbe_handle_t *lbh, char *name, int options)
203{
204 zfs_handle_t *fs;
205 char path[BE_MAXPATHLEN];
206 char *p;
207 int err, force, mounted;

--- 26 unchanged lines hidden (view full) ---

234 /* Check if mounted, unmount if force is specified */
235 if ((mounted = zfs_is_mounted(fs, NULL)) != 0) {
236 if (force)
237 zfs_unmount(fs, NULL, 0);
238 else
239 return (set_error(lbh, BE_ERR_DESTROYMNT));
240 }
241
242 if ((err = be_destroy_cb(fs, NULL)) != 0) {
243 /* Children are still present or the mount is referenced */
244 if (err == EBUSY)
245 return (set_error(lbh, BE_ERR_DESTROYMNT));
246 return (set_error(lbh, BE_ERR_UNKNOWN));
247 }
231
248
232 /* XXX TODO: convert this to use zfs_iter_children first for deep BEs */
233 /* XXX Note: errno 16 (device busy) occurs when chilren are present */
234 if ((err = zfs_destroy(fs, false)) != 0)
235 fprintf(stderr, "delete failed errno: %d\n", errno);
236
237 return (err);
249 return (0);
238}
239
240
241int
242be_snapshot(libbe_handle_t *lbh, const char *source, const char *snap_name,
243 bool recursive, char *result)
244{
245 char buf[BE_MAXPATHLEN];

--- 634 unchanged lines hidden ---
250}
251
252
253int
254be_snapshot(libbe_handle_t *lbh, const char *source, const char *snap_name,
255 bool recursive, char *result)
256{
257 char buf[BE_MAXPATHLEN];

--- 634 unchanged lines hidden ---