dsl_userhold.c (248571) | dsl_userhold.c (249195) |
---|---|
1/* 2 * CDDL HEADER START 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 --- 6 unchanged lines hidden (view full) --- 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 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. | 1/* 2 * CDDL HEADER START 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 --- 6 unchanged lines hidden (view full) --- 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 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. |
23 * Copyright (c) 2012 by Delphix. All rights reserved. | 23 * Copyright (c) 2013 by Delphix. All rights reserved. |
24 */ 25 26#include <sys/zfs_context.h> 27#include <sys/dsl_userhold.h> 28#include <sys/dsl_dataset.h> 29#include <sys/dsl_destroy.h> 30#include <sys/dsl_synctask.h> 31#include <sys/dmu_tx.h> --- 30 unchanged lines hidden (view full) --- 62 /* tags must be unique (if ds already exists) */ 63 if (ds != NULL) { 64 mutex_enter(&ds->ds_lock); 65 if (ds->ds_phys->ds_userrefs_obj != 0) { 66 uint64_t value; 67 error = zap_lookup(mos, ds->ds_phys->ds_userrefs_obj, 68 htag, 8, 1, &value); 69 if (error == 0) | 24 */ 25 26#include <sys/zfs_context.h> 27#include <sys/dsl_userhold.h> 28#include <sys/dsl_dataset.h> 29#include <sys/dsl_destroy.h> 30#include <sys/dsl_synctask.h> 31#include <sys/dmu_tx.h> --- 30 unchanged lines hidden (view full) --- 62 /* tags must be unique (if ds already exists) */ 63 if (ds != NULL) { 64 mutex_enter(&ds->ds_lock); 65 if (ds->ds_phys->ds_userrefs_obj != 0) { 66 uint64_t value; 67 error = zap_lookup(mos, ds->ds_phys->ds_userrefs_obj, 68 htag, 8, 1, &value); 69 if (error == 0) |
70 error = EEXIST; | 70 error = SET_ERROR(EEXIST); |
71 else if (error == ENOENT) 72 error = 0; 73 } 74 mutex_exit(&ds->ds_lock); 75 } 76 77 return (error); 78} 79 80static int 81dsl_dataset_user_hold_check(void *arg, dmu_tx_t *tx) 82{ 83 dsl_dataset_user_hold_arg_t *dduha = arg; 84 dsl_pool_t *dp = dmu_tx_pool(tx); 85 nvpair_t *pair; 86 int rv = 0; 87 88 if (spa_version(dp->dp_spa) < SPA_VERSION_USERREFS) | 71 else if (error == ENOENT) 72 error = 0; 73 } 74 mutex_exit(&ds->ds_lock); 75 } 76 77 return (error); 78} 79 80static int 81dsl_dataset_user_hold_check(void *arg, dmu_tx_t *tx) 82{ 83 dsl_dataset_user_hold_arg_t *dduha = arg; 84 dsl_pool_t *dp = dmu_tx_pool(tx); 85 nvpair_t *pair; 86 int rv = 0; 87 88 if (spa_version(dp->dp_spa) < SPA_VERSION_USERREFS) |
89 return (ENOTSUP); | 89 return (SET_ERROR(ENOTSUP)); |
90 91 for (pair = nvlist_next_nvpair(dduha->dduha_holds, NULL); pair != NULL; 92 pair = nvlist_next_nvpair(dduha->dduha_holds, pair)) { 93 int error = 0; 94 dsl_dataset_t *ds; 95 char *htag; 96 97 /* must be a snapshot */ 98 if (strchr(nvpair_name(pair), '@') == NULL) | 90 91 for (pair = nvlist_next_nvpair(dduha->dduha_holds, NULL); pair != NULL; 92 pair = nvlist_next_nvpair(dduha->dduha_holds, pair)) { 93 int error = 0; 94 dsl_dataset_t *ds; 95 char *htag; 96 97 /* must be a snapshot */ 98 if (strchr(nvpair_name(pair), '@') == NULL) |
99 error = EINVAL; | 99 error = SET_ERROR(EINVAL); |
100 101 if (error == 0) 102 error = nvpair_value_string(pair, &htag); 103 if (error == 0) { 104 error = dsl_dataset_hold(dp, 105 nvpair_name(pair), FTAG, &ds); 106 } 107 if (error == 0) { --- 105 unchanged lines hidden (view full) --- 213 nvpair_t *pair; 214 objset_t *mos = ds->ds_dir->dd_pool->dp_meta_objset; 215 int error; 216 int numholds = 0; 217 218 *todelete = B_FALSE; 219 220 if (!dsl_dataset_is_snapshot(ds)) | 100 101 if (error == 0) 102 error = nvpair_value_string(pair, &htag); 103 if (error == 0) { 104 error = dsl_dataset_hold(dp, 105 nvpair_name(pair), FTAG, &ds); 106 } 107 if (error == 0) { --- 105 unchanged lines hidden (view full) --- 213 nvpair_t *pair; 214 objset_t *mos = ds->ds_dir->dd_pool->dp_meta_objset; 215 int error; 216 int numholds = 0; 217 218 *todelete = B_FALSE; 219 220 if (!dsl_dataset_is_snapshot(ds)) |
221 return (EINVAL); | 221 return (SET_ERROR(EINVAL)); |
222 223 zapobj = ds->ds_phys->ds_userrefs_obj; 224 if (zapobj == 0) | 222 223 zapobj = ds->ds_phys->ds_userrefs_obj; 224 if (zapobj == 0) |
225 return (ESRCH); | 225 return (SET_ERROR(ESRCH)); |
226 227 for (pair = nvlist_next_nvpair(holds, NULL); pair != NULL; 228 pair = nvlist_next_nvpair(holds, pair)) { 229 /* Make sure the hold exists */ 230 uint64_t tmp; 231 error = zap_lookup(mos, zapobj, nvpair_name(pair), 8, 1, &tmp); 232 if (error == ENOENT) | 226 227 for (pair = nvlist_next_nvpair(holds, NULL); pair != NULL; 228 pair = nvlist_next_nvpair(holds, pair)) { 229 /* Make sure the hold exists */ 230 uint64_t tmp; 231 error = zap_lookup(mos, zapobj, nvpair_name(pair), 8, 1, &tmp); 232 if (error == ENOENT) |
233 error = ESRCH; | 233 error = SET_ERROR(ESRCH); |
234 if (error != 0) 235 return (error); 236 numholds++; 237 } 238 239 if (DS_IS_DEFER_DESTROY(ds) && ds->ds_phys->ds_num_children == 1 && 240 ds->ds_userrefs == numholds) { 241 /* we need to destroy the snapshot as well */ 242 243 if (dsl_dataset_long_held(ds)) | 234 if (error != 0) 235 return (error); 236 numholds++; 237 } 238 239 if (DS_IS_DEFER_DESTROY(ds) && ds->ds_phys->ds_num_children == 1 && 240 ds->ds_userrefs == numholds) { 241 /* we need to destroy the snapshot as well */ 242 243 if (dsl_dataset_long_held(ds)) |
244 return (EBUSY); | 244 return (SET_ERROR(EBUSY)); |
245 *todelete = B_TRUE; 246 } 247 return (0); 248} 249 250static int 251dsl_dataset_user_release_check(void *arg, dmu_tx_t *tx) 252{ --- 9 unchanged lines hidden (view full) --- 262 pair = nvlist_next_nvpair(ddura->ddura_holds, pair)) { 263 const char *name = nvpair_name(pair); 264 int error; 265 dsl_dataset_t *ds; 266 nvlist_t *holds; 267 268 error = nvpair_value_nvlist(pair, &holds); 269 if (error != 0) | 245 *todelete = B_TRUE; 246 } 247 return (0); 248} 249 250static int 251dsl_dataset_user_release_check(void *arg, dmu_tx_t *tx) 252{ --- 9 unchanged lines hidden (view full) --- 262 pair = nvlist_next_nvpair(ddura->ddura_holds, pair)) { 263 const char *name = nvpair_name(pair); 264 int error; 265 dsl_dataset_t *ds; 266 nvlist_t *holds; 267 268 error = nvpair_value_nvlist(pair, &holds); 269 if (error != 0) |
270 return (EINVAL); | 270 return (SET_ERROR(EINVAL)); |
271 272 error = dsl_dataset_hold(dp, name, FTAG, &ds); 273 if (error == 0) { 274 boolean_t deleteme; 275 error = dsl_dataset_user_release_check_one(ds, 276 holds, &deleteme); 277 if (error == 0 && deleteme) { 278 fnvlist_add_boolean(ddura->ddura_todelete, --- 258 unchanged lines hidden --- | 271 272 error = dsl_dataset_hold(dp, name, FTAG, &ds); 273 if (error == 0) { 274 boolean_t deleteme; 275 error = dsl_dataset_user_release_check_one(ds, 276 holds, &deleteme); 277 if (error == 0 && deleteme) { 278 fnvlist_add_boolean(ddura->ddura_todelete, --- 258 unchanged lines hidden --- |