19fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States /* 29fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * CDDL HEADER START 39fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * 49fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * The contents of this file are subject to the terms of the 59fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * Common Development and Distribution License (the "License"). 69fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * You may not use this file except in compliance with the License. 79fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * 89fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 99fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * or http://www.opensolaris.org/os/licensing. 109fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * See the License for the specific language governing permissions 119fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * and limitations under the License. 129fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * 139fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * When distributing Covered Code, include this CDDL HEADER in each 149fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 159fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * If applicable, add the following below this CDDL HEADER, with the 169fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * fields enclosed by brackets "[]" replaced with your own identifying 179fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * information: Portions Copyright [yyyy] [name of copyright owner] 189fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * 199fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * CDDL HEADER END 209fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States */ 21148c5f43SAlan Wright 229fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States /* 23c5866007SKeyur Desai * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. 2429e6af5cSAlek Pinchuk * Copyright 2014 Nexenta Systems, Inc. All rights reserved. 259fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States */ 26148c5f43SAlan Wright 279fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States #include <stdio.h> 289fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States #include <stdlib.h> 299fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States #include <fcntl.h> 309fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States #include <attr.h> 319fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States #include <unistd.h> 329fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States #include <libuutil.h> 339fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States #include <libzfs.h> 349fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States #include <assert.h> 359fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States #include <stddef.h> 369fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States #include <strings.h> 379fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States #include <errno.h> 389fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States #include <synch.h> 399fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States #include <smbsrv/smb_xdr.h> 409fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States #include <smbsrv/libmlsvc.h> 419fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States #include <smbsrv/smb_idmap.h> 429fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States #include <mlsvc.h> 439fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States #include <sys/avl.h> 449fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 459fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States /* 469fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * smb_quota subsystem interface - mlsvc.h 479fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * --------------------------------------- 489fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * Management of the smb_quota_fs_list (see below). 499fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * smb_quota_init 509fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * smb_quota_fini 519fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * smb_quota_add_fs 529fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * smb_quota_remove_fs 539fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * 549fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * smb_quota public interface - libmlsvc.h 559fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * --------------------------------------- 569fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * Handling of requests to query and set quota data on a filesystem. 579fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * smb_quota_query - query user/group quotas on a filesystem 589fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * smb_quota_set - set user/group quotas ona filesystem 599fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * smb_quota_free - delete the quota list created in smb_quota_query 609fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States */ 619fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 629fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States /* 639fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * Querying user & group quotas - smb_quota_query 649fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * 659fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * In order to fulfill the quota query requests that can be received 669fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * from clients, it is required that the quota data can be provided in 679fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * a well defined and consistent order, and that a request can specify 689fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * at which quota entry to begin the query. 699fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * 709fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * Quota Tree 719fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * Since the file system does not support the above, an avl tree is 729fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * populated with the file system's user and group quota data, and 739fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * then used to provide the data to respond to query requests. The 749fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * avl tree is indexed by the SID. 759fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * Each node of the avl tree is an smb_quota_t structure. 769fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * 779fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * Quota List 789fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * There is a list of avl trees, one per file system. 799fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * Each node in the list is an smb_quota_tree_t structure. 809fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * The list is created via a call to smb_quota_init() when the library 819fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * is initialized, and destroyed via a call to smb_quota_fini() when 829fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * the library is fini'd. 839fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * 849fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * An avl tree for a specific file system is created and added to the 859fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * list via a call to smb_quota_add_fs() when the file system is shared, 869fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * and removed from the list via a call to smb_quota_remove_fs() when 879fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * the file system is unshared. 889fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * 899fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * An avl tree is (re)populated, if required, whenever a quota request 909fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * (EXCLUDING a resume request) is received for its filesystem. The 919fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * avl tree is considered to be expired (needs to be repopulated) if 929fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * either of the following have occurred since it was last (re)populated: 939fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * - SMB_QUOTA_REFRESH seconds have elapsed OR 949fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * - a quota set operation has been performed on its file system 959fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * 969fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * In order to perform a smb_quota_query/set operation on a file system 979fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * the appropriate quota tree must be identified and locked via a call 989fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * to smb_quota_tree_lookup(), The quota tree is locked (qt_locked == B_TRUE) 999fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * until the caller releases it via a call to smb_quota_tree_release(). 1009fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States */ 1019fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 1029fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States /* 1039fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * smb_quota_tree_t 1049fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * Represents an avl tree of user quotas for a file system. 1059fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * 1069fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * qt_refcnt - a count of the number of users of the tree. 1079fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * qt_refcnt is also incremented and decremented when the tree is 1089fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * added to and removed from the quota list. 1099fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * The tree cannot be deleted until this count is zero. 1109fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * 1119fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * qt_sharecnt - a count of the shares of the file system which the 1129fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * tree represents. smb_quota_remove_fs() cannot remove the tree from 1139fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * removed from the quota list until this count is zero. 1149fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * 1159fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * qt_locked - B_TRUE if someone is currently using the tree, in 1169fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * which case a lookup will wait for the tree to become available. 1179fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States */ 1189fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States typedef struct smb_quota_tree { 1199fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States list_node_t qt_node; 1209fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States char *qt_path; 1219fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States time_t qt_timestamp; 1229fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States uint32_t qt_refcnt; 1239fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States uint32_t qt_sharecnt; 1249fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States boolean_t qt_locked; 1259fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States avl_tree_t qt_avl; 1269fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States mutex_t qt_mutex; 1279fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States }smb_quota_tree_t; 1289fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 1299fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States /* 1309fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * smb_quota_fs_list 1319fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * list of quota trees; one per shared file system. 1329fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States */ 1339fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States static list_t smb_quota_fs_list; 1349fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States static boolean_t smb_quota_list_init = B_FALSE; 1359fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States static boolean_t smb_quota_shutdown = B_FALSE; 136c5866007SKeyur Desai static mutex_t smb_quota_list_mutex = DEFAULTMUTEX; 1379fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States static cond_t smb_quota_list_condvar; 1389fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States static uint32_t smb_quota_tree_cnt = 0; 1399fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States static int smb_quota_fini_timeout = 1; /* seconds */ 1409fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 1419fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States /* 1429fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * smb_quota_zfs_handle_t 1439fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * handle to zfs library and dataset 1449fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States */ 1459fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States typedef struct smb_quota_zfs_handle { 1469fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States libzfs_handle_t *z_lib; 1479fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States zfs_handle_t *z_fs; 1489fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States } smb_quota_zfs_handle_t; 1499fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 1509fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States /* 1519fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * smb_quota_zfs_arg_t 1529fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * arg passed to zfs callback when querying quota properties 1539fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States */ 1549fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States typedef struct smb_quota_zfs_arg { 1559fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States zfs_userquota_prop_t qa_prop; 1569fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States avl_tree_t *qa_avl; 1579fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States } smb_quota_zfs_arg_t; 1589fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 1599fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States static void smb_quota_add_ctrldir(const char *); 1609fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States static void smb_quota_remove_ctrldir(const char *); 1619fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 1629fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States static smb_quota_tree_t *smb_quota_tree_create(const char *); 1639fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States static void smb_quota_tree_delete(smb_quota_tree_t *); 1649fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 1659fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States static smb_quota_tree_t *smb_quota_tree_lookup(const char *); 1669fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States static void smb_quota_tree_release(smb_quota_tree_t *); 1679fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States static boolean_t smb_quota_tree_match(smb_quota_tree_t *, const char *); 1689fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States static int smb_quota_sid_cmp(const void *, const void *); 1699fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States static uint32_t smb_quota_tree_populate(smb_quota_tree_t *); 1709fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States static boolean_t smb_quota_tree_expired(smb_quota_tree_t *); 1719fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States static void smb_quota_tree_set_expired(smb_quota_tree_t *); 1729fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 1739fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States static uint32_t smb_quota_zfs_init(const char *, smb_quota_zfs_handle_t *); 1749fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States static void smb_quota_zfs_fini(smb_quota_zfs_handle_t *); 1759fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States static uint32_t smb_quota_zfs_get_quotas(smb_quota_tree_t *); 1769fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States static int smb_quota_zfs_callback(void *, const char *, uid_t, uint64_t); 1779fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States static uint32_t smb_quota_zfs_set_quotas(smb_quota_tree_t *, smb_quota_set_t *); 1789fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States static int smb_quota_sidstr(uint32_t, zfs_userquota_prop_t, char *); 1799fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States static uint32_t smb_quota_sidtype(smb_quota_tree_t *, char *); 1809fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States static int smb_quota_getid(char *, uint32_t, uint32_t *); 1819fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 1829fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States static uint32_t smb_quota_query_all(smb_quota_tree_t *, 1839fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States smb_quota_query_t *, smb_quota_response_t *); 1849fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States static uint32_t smb_quota_query_list(smb_quota_tree_t *, 1859fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States smb_quota_query_t *, smb_quota_response_t *); 1869fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 1879fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States #define SMB_QUOTA_REFRESH 2 1889fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States #define SMB_QUOTA_CMD_LENGTH 21 1899fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States #define SMB_QUOTA_CMD_STR_LENGTH SMB_SID_STRSZ+SMB_QUOTA_CMD_LENGTH 1909fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 1919fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States /* 1929fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * In order to display the quota properties tab, windows clients 1939fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * check for the existence of the quota control file. 1949fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States */ 1959fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States #define SMB_QUOTA_CNTRL_DIR ".$EXTEND" 1969fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States #define SMB_QUOTA_CNTRL_FILE "$QUOTA" 1979fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States #define SMB_QUOTA_CNTRL_INDEX_XATTR "SUNWsmb:$Q:$INDEX_ALLOCATION" 19829e6af5cSAlek Pinchuk /* 19929e6af5cSAlek Pinchuk * Note: this line needs to have the same format as what acl_totext() returns. 20029e6af5cSAlek Pinchuk */ 20129e6af5cSAlek Pinchuk #define SMB_QUOTA_CNTRL_PERM "everyone@:rw-p--aARWc--s:-------:allow" 2029fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 2039fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States /* 2049fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * smb_quota_init 2059fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * Initialize the list to hold the quota trees. 2069fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States */ 2079fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States void 2089fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States smb_quota_init(void) 2099fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States { 2109fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States (void) mutex_lock(&smb_quota_list_mutex); 2119fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States if (!smb_quota_list_init) { 2129fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States list_create(&smb_quota_fs_list, sizeof (smb_quota_tree_t), 2139fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States offsetof(smb_quota_tree_t, qt_node)); 2149fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States smb_quota_list_init = B_TRUE; 2159fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States smb_quota_shutdown = B_FALSE; 2169fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States } 2179fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States (void) mutex_unlock(&smb_quota_list_mutex); 2189fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States } 2199fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 2209fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States /* 2219fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * smb_quota_fini 2229fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * 2239fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * Wait for each quota tree to not be in use (qt_refcnt == 1) 2249fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * then remove it from the list and delete it. 2259fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States */ 2269fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States void 2279fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States smb_quota_fini(void) 2289fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States { 2299fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States smb_quota_tree_t *qtree, *qtree_next; 2309fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States boolean_t remove; 2319fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States struct timespec tswait; 2329fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States tswait.tv_sec = smb_quota_fini_timeout; 2339fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States tswait.tv_nsec = 0; 2349fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 2359fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States (void) mutex_lock(&smb_quota_list_mutex); 2369fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States smb_quota_shutdown = B_TRUE; 2379fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 2389fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States if (!smb_quota_list_init) { 2399fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States (void) mutex_unlock(&smb_quota_list_mutex); 2409fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States return; 2419fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States } 2429fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 2439fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States (void) cond_broadcast(&smb_quota_list_condvar); 2449fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 245c5866007SKeyur Desai while (!list_is_empty(&smb_quota_fs_list)) { 2469fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States qtree = list_head(&smb_quota_fs_list); 2479fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States while (qtree != NULL) { 2489fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States qtree_next = list_next(&smb_quota_fs_list, qtree); 2499fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 2509fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States (void) mutex_lock(&qtree->qt_mutex); 2519fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States remove = (qtree->qt_refcnt == 1); 2529fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States if (remove) { 2539fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States list_remove(&smb_quota_fs_list, qtree); 2549fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States --qtree->qt_refcnt; 2559fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States } 2569fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States (void) mutex_unlock(&qtree->qt_mutex); 2579fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 2589fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States if (remove) 2599fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States smb_quota_tree_delete(qtree); 2609fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 2619fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States qtree = qtree_next; 2629fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States } 2639fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 264c5866007SKeyur Desai if (!list_is_empty(&smb_quota_fs_list)) { 2659fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States if (cond_reltimedwait(&smb_quota_list_condvar, 2669fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States &smb_quota_list_mutex, &tswait) == ETIME) { 2679fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States syslog(LOG_WARNING, 2689fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States "quota shutdown timeout expired"); 2699fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States break; 2709fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States } 2719fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States } 2729fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States } 2739fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 2749fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States if (list_is_empty(&smb_quota_fs_list)) { 2759fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States list_destroy(&smb_quota_fs_list); 2769fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States smb_quota_list_init = B_FALSE; 2779fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States } 2789fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 2799fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States (void) mutex_unlock(&smb_quota_list_mutex); 2809fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States } 2819fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 2829fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States /* 2839fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * smb_quota_add_fs 2849fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * 2859fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * If there is not a quota tree representing the specified path, 2869fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * create one and add it to the list. 2879fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States */ 2889fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States void 2899fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States smb_quota_add_fs(const char *path) 2909fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States { 2919fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States smb_quota_tree_t *qtree; 2929fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 2939fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States (void) mutex_lock(&smb_quota_list_mutex); 2949fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 2959fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States if (!smb_quota_list_init || smb_quota_shutdown) { 2969fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States (void) mutex_unlock(&smb_quota_list_mutex); 2979fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States return; 2989fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States } 2999fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 3009fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States qtree = list_head(&smb_quota_fs_list); 3019fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States while (qtree != NULL) { 3029fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States if (smb_quota_tree_match(qtree, path)) { 3039fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States (void) mutex_lock(&qtree->qt_mutex); 3049fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States ++qtree->qt_sharecnt; 3059fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States (void) mutex_unlock(&qtree->qt_mutex); 3069fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States break; 3079fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States } 3089fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States qtree = list_next(&smb_quota_fs_list, qtree); 3099fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States } 3109fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 3119fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States if (qtree == NULL) { 3129fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States qtree = smb_quota_tree_create(path); 3139fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States if (qtree) 3149fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States list_insert_head(&smb_quota_fs_list, (void *)qtree); 3159fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States } 3169fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 3179fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States if (qtree) 3189fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States smb_quota_add_ctrldir(path); 3199fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 3209fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States (void) mutex_unlock(&smb_quota_list_mutex); 3219fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States } 3229fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 3239fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States /* 3249fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * smb_quota_remove_fs 3259fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * 3269fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * If this is the last share that the quota tree represents 3279fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * (qtree->qt_sharecnt == 0) remove the qtree from the list. 3289fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * The qtree will be deleted if/when there is nobody using it 3299fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * (qtree->qt_refcnt == 0). 3309fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States */ 3319fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States void 3329fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States smb_quota_remove_fs(const char *path) 3339fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States { 3349fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States smb_quota_tree_t *qtree; 3359fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States boolean_t delete = B_FALSE; 3369fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 3379fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States (void) mutex_lock(&smb_quota_list_mutex); 3389fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 3399fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States if (!smb_quota_list_init || smb_quota_shutdown) { 3409fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States (void) mutex_unlock(&smb_quota_list_mutex); 3419fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States return; 3429fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States } 3439fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 3449fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States qtree = list_head(&smb_quota_fs_list); 3459fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States while (qtree != NULL) { 3469fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States assert(qtree->qt_refcnt > 0); 3479fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States if (smb_quota_tree_match(qtree, path)) { 3489fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States (void) mutex_lock(&qtree->qt_mutex); 3499fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States --qtree->qt_sharecnt; 3509fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States if (qtree->qt_sharecnt == 0) { 3519fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States list_remove(&smb_quota_fs_list, (void *)qtree); 3529fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States smb_quota_remove_ctrldir(qtree->qt_path); 3539fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States --(qtree->qt_refcnt); 3549fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States delete = (qtree->qt_refcnt == 0); 3559fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States } 3569fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States (void) mutex_unlock(&qtree->qt_mutex); 3579fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States if (delete) 3589fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States smb_quota_tree_delete(qtree); 3599fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States break; 3609fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States } 3619fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States qtree = list_next(&smb_quota_fs_list, qtree); 3629fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States } 3639fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States (void) mutex_unlock(&smb_quota_list_mutex); 3649fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States } 3659fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 3669fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States /* 3679fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * smb_quota_query 3689fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * 3699fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * Get list of user/group quotas entries. 3709fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * Request->qq_query_op determines whether to get quota entries 3719fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * for the specified SIDs (smb_quota_query_list) OR to get all 3729fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * quota entries, optionally starting at a specified SID. 3739fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * 3749fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * Returns NT_STATUS codes. 3759fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States */ 3769fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States uint32_t 3779fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States smb_quota_query(smb_quota_query_t *request, smb_quota_response_t *reply) 3789fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States { 3799fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States uint32_t status; 3809fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States smb_quota_tree_t *qtree; 3819fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States smb_quota_query_op_t query_op = request->qq_query_op; 3829fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 3839fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States list_create(&reply->qr_quota_list, sizeof (smb_quota_t), 3849fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States offsetof(smb_quota_t, q_list_node)); 3859fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 3869fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States qtree = smb_quota_tree_lookup(request->qq_root_path); 3879fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States if (qtree == NULL) 3889fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States return (NT_STATUS_INVALID_PARAMETER); 3899fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 3909fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States /* If NOT resuming a previous query all, refresh qtree if required */ 3919fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States if ((query_op != SMB_QUOTA_QUERY_ALL) || (request->qq_restart)) { 3929fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States status = smb_quota_tree_populate(qtree); 3939fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States if (status != NT_STATUS_SUCCESS) { 3949fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States smb_quota_tree_release(qtree); 3959fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States return (status); 3969fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States } 3979fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States } 3989fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 3999fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States switch (query_op) { 4009fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States case SMB_QUOTA_QUERY_SIDLIST: 4019fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States status = smb_quota_query_list(qtree, request, reply); 4029fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States break; 4039fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States case SMB_QUOTA_QUERY_STARTSID: 4049fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States case SMB_QUOTA_QUERY_ALL: 4059fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States status = smb_quota_query_all(qtree, request, reply); 4069fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States break; 4079fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States case SMB_QUOTA_QUERY_INVALID_OP: 4089fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States default: 4099fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States status = NT_STATUS_INVALID_PARAMETER; 4109fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States break; 4119fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States } 4129fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 4139fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States smb_quota_tree_release(qtree); 4149fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 4159fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States return (status); 4169fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States } 4179fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 4189fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States /* 4199fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * smb_quota_set 4209fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * 4219fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * Set the list of quota entries. 4229fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States */ 4239fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States uint32_t 4249fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States smb_quota_set(smb_quota_set_t *request) 4259fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States { 4269fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States uint32_t status; 4279fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States smb_quota_tree_t *qtree; 4289fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 4299fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States qtree = smb_quota_tree_lookup(request->qs_root_path); 4309fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States if (qtree == NULL) 4319fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States return (NT_STATUS_INVALID_PARAMETER); 4329fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 4339fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States status = smb_quota_zfs_set_quotas(qtree, request); 4349fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 4359fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States smb_quota_tree_set_expired(qtree); 4369fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States smb_quota_tree_release(qtree); 4379fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 4389fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States return (status); 4399fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States } 4409fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 4419fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States /* 4429fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * smb_quota_free 4439fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * 4449fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * This method frees quota entries. 4459fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States */ 4469fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States void 4479fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States smb_quota_free(smb_quota_response_t *reply) 4489fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States { 4499fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States list_t *list = &reply->qr_quota_list; 4509fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States smb_quota_t *quota; 4519fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 4529fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States while ((quota = list_head(list)) != NULL) { 4539fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States list_remove(list, quota); 4549fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States free(quota); 4559fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States } 4569fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 4579fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States list_destroy(list); 4589fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States } 4599fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 4609fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States /* 4619fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * smb_quota_query_all 4629fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * 4639fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * Query quotas sequentially from tree, optionally starting at a 4649fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * specified sid. If request->qq_single is TRUE only one quota 4659fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * should be returned, otherwise up to request->qq_max_quota 4669fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * should be returned. 4679fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * 4689fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * SMB_QUOTA_QUERY_STARTSID 4699fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * The query should start at the startsid, the first sid in 4709fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * request->qq_sid_list. 4719fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * 4729fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * SMQ_QUOTA_QUERY_ALL 4739fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * If request->qq_restart the query should restart at the start 4749fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * of the avl tree. Otherwise the first sid in request->qq_sid_list 4759fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * is the resume sid and the query should start at the tree entry 4769fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * after the one it refers to. 4779fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * 4789fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * Returns NT_STATUS codes. 4799fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States */ 4809fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States static uint32_t 4819fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States smb_quota_query_all(smb_quota_tree_t *qtree, smb_quota_query_t *request, 4829fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States smb_quota_response_t *reply) 4839fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States { 4849fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States avl_tree_t *avl_tree = &qtree->qt_avl; 4859fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States avl_index_t where; 4869fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States list_t *sid_list, *quota_list; 4879fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States smb_quota_sid_t *sid; 4889fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States smb_quota_t *quota, *quotal, key; 4899fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States uint32_t count; 4909fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 4919fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States /* find starting sid */ 4929fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States if (request->qq_query_op == SMB_QUOTA_QUERY_STARTSID) { 4939fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States sid_list = &request->qq_sid_list; 4949fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States sid = list_head(sid_list); 4959fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States (void) strlcpy(key.q_sidstr, sid->qs_sidstr, SMB_SID_STRSZ); 4969fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States quota = avl_find(avl_tree, &key, &where); 4979fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States if (quota == NULL) 4989fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States return (NT_STATUS_INVALID_PARAMETER); 4999fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States } else if (request->qq_restart) { 5009fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States quota = avl_first(avl_tree); 5019fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States if (quota == NULL) 502148c5f43SAlan Wright return (NT_STATUS_NO_MORE_ENTRIES); 5039fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States } else { 5049fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States sid_list = &request->qq_sid_list; 5059fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States sid = list_head(sid_list); 5069fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States (void) strlcpy(key.q_sidstr, sid->qs_sidstr, SMB_SID_STRSZ); 5079fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States quota = avl_find(avl_tree, &key, &where); 5089fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States if (quota == NULL) 5099fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States return (NT_STATUS_INVALID_PARAMETER); 5109fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States quota = AVL_NEXT(avl_tree, quota); 5119fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States if (quota == NULL) 512148c5f43SAlan Wright return (NT_STATUS_NO_MORE_ENTRIES); 5139fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States } 5149fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 5159fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States if ((request->qq_single) && (request->qq_max_quota > 1)) 5169fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States request->qq_max_quota = 1; 5179fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 5189fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States quota_list = &reply->qr_quota_list; 5199fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States count = 0; 5209fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States while (quota) { 5219fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States if (count >= request->qq_max_quota) 5229fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States break; 5239fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 5249fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States quotal = malloc(sizeof (smb_quota_t)); 5259fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States if (quotal == NULL) 5269fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States return (NT_STATUS_NO_MEMORY); 5279fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States bcopy(quota, quotal, sizeof (smb_quota_t)); 5289fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 5299fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States list_insert_tail(quota_list, quotal); 5309fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States ++count; 5319fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 5329fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States quota = AVL_NEXT(avl_tree, quota); 5339fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States } 5349fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 5359fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States return (NT_STATUS_SUCCESS); 5369fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States } 5379fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 5389fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States /* 5399fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * smb_quota_query_list 5409fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * 5419fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * Iterate through request sid list querying the avl tree for each. 5429fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * Insert an entry in the reply quota list for each sid. 5439fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * For any sid that cannot be found in the avl tree, the reply 5449fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * quota list entry should contain zeros. 5459fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States */ 5469fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States static uint32_t 5479fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States smb_quota_query_list(smb_quota_tree_t *qtree, smb_quota_query_t *request, 5489fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States smb_quota_response_t *reply) 5499fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States { 5509fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States avl_tree_t *avl_tree = &qtree->qt_avl; 5519fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States avl_index_t where; 5529fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States list_t *sid_list, *quota_list; 5539fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States smb_quota_sid_t *sid; 5549fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States smb_quota_t *quota, *quotal, key; 5559fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 5569fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States quota_list = &reply->qr_quota_list; 5579fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States sid_list = &request->qq_sid_list; 5589fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States sid = list_head(sid_list); 5599fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States while (sid) { 5609fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States quotal = malloc(sizeof (smb_quota_t)); 5619fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States if (quotal == NULL) 5629fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States return (NT_STATUS_NO_MEMORY); 5639fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 5649fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States (void) strlcpy(key.q_sidstr, sid->qs_sidstr, SMB_SID_STRSZ); 5659fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States quota = avl_find(avl_tree, &key, &where); 5669fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States if (quota) { 5679fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States bcopy(quota, quotal, sizeof (smb_quota_t)); 5689fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States } else { 5699fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States bzero(quotal, sizeof (smb_quota_t)); 5709fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States (void) strlcpy(quotal->q_sidstr, sid->qs_sidstr, 5719fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States SMB_SID_STRSZ); 5729fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States } 5739fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 5749fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States list_insert_tail(quota_list, quotal); 5759fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States sid = list_next(sid_list, sid); 5769fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States } 5779fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 5789fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States return (NT_STATUS_SUCCESS); 5799fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States } 5809fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 5819fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States /* 5829fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * smb_quota_zfs_set_quotas 5839fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * 5849fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * This method sets the list of quota entries. 5859fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * 5869fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * A quota list or threshold value of SMB_QUOTA_UNLIMITED means that 5879fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * the user / group does not have a quota limit. In ZFS this maps to 5889fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * 0 (none). 5899fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * A quota list or threshold value of (SMB_QUOTA_UNLIMITED - 1) means 5909fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * that the user / group quota should be removed. In ZFS this maps to 5919fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * 0 (none). 5929fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States */ 5939fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States static uint32_t 5949fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States smb_quota_zfs_set_quotas(smb_quota_tree_t *qtree, smb_quota_set_t *request) 5959fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States { 5969fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States smb_quota_zfs_handle_t zfs_hdl; 5979fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States char *typestr, qsetstr[SMB_QUOTA_CMD_STR_LENGTH]; 5989fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States char qlimit[SMB_QUOTA_CMD_LENGTH]; 5999fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States list_t *quota_list; 6009fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States smb_quota_t *quota; 6019fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States uint32_t id; 6029fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States uint32_t status = NT_STATUS_SUCCESS; 6039fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States uint32_t sidtype; 6049fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 6059fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States status = smb_quota_zfs_init(request->qs_root_path, &zfs_hdl); 6069fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States if (status != NT_STATUS_SUCCESS) 6079fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States return (status); 6089fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 6099fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States quota_list = &request->qs_quota_list; 6109fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States quota = list_head(quota_list); 6119fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 6129fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States while (quota) { 6139fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States if ((quota->q_limit == SMB_QUOTA_UNLIMITED) || 6149fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States (quota->q_limit == (SMB_QUOTA_UNLIMITED - 1))) { 6159fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States quota->q_limit = 0; 6169fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States } 6179fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States (void) snprintf(qlimit, SMB_QUOTA_CMD_LENGTH, "%llu", 6189fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States quota->q_limit); 6199fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 6209fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States sidtype = smb_quota_sidtype(qtree, quota->q_sidstr); 6219fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States switch (sidtype) { 6229fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States case SidTypeUser: 6239fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States typestr = "userquota"; 6249fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States break; 6259fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States case SidTypeWellKnownGroup: 6269fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States case SidTypeGroup: 6279fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States case SidTypeAlias: 6289fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States typestr = "groupquota"; 6299fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States break; 6309fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States default: 6319fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States syslog(LOG_WARNING, "Failed to set quota for %s: " 6329fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States "%s (%d) not valid for quotas", quota->q_sidstr, 6339fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States smb_sid_type2str(sidtype), sidtype); 6349fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States quota = list_next(quota_list, quota); 6359fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States continue; 6369fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States } 6379fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 6389fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States if ((smb_quota_getid(quota->q_sidstr, sidtype, &id) == 0) && 6399fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States !(IDMAP_ID_IS_EPHEMERAL(id))) { 6409fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States (void) snprintf(qsetstr, SMB_QUOTA_CMD_STR_LENGTH, 6419fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States "%s@%d", typestr, id); 6429fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States } else { 6439fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States (void) snprintf(qsetstr, SMB_QUOTA_CMD_STR_LENGTH, 6449fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States "%s@%s", typestr, quota->q_sidstr); 6459fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States } 6469fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 6479fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States errno = 0; 6489fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States if (zfs_prop_set(zfs_hdl.z_fs, qsetstr, qlimit) != 0) { 6499fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States syslog(LOG_WARNING, "Failed to set quota for %s: %s", 6509fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States quota->q_sidstr, strerror(errno)); 6519fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States status = NT_STATUS_INVALID_PARAMETER; 6529fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States break; 6539fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States } 6549fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 6559fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States quota = list_next(quota_list, quota); 6569fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States } 6579fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 6589fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States smb_quota_zfs_fini(&zfs_hdl); 6599fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States return (status); 6609fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States } 6619fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 6629fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States /* 6639fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * smb_quota_sidtype 6649fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * 6659fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * Determine the type of the sid. If the sid exists in 6669fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * the qtree get its type from there, otherwise do an 6679fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * lsa_lookup_sid(). 6689fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States */ 6699fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States static uint32_t 6709fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States smb_quota_sidtype(smb_quota_tree_t *qtree, char *sidstr) 6719fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States { 6729fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States smb_quota_t key, *quota; 6739fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States avl_index_t where; 6749fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States smb_sid_t *sid = NULL; 6759fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States smb_account_t ainfo; 6769fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States uint32_t sidtype = SidTypeUnknown; 6779fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 6789fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States (void) strlcpy(key.q_sidstr, sidstr, SMB_SID_STRSZ); 6799fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States quota = avl_find(&qtree->qt_avl, &key, &where); 6809fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States if (quota) 6819fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States return (quota->q_sidtype); 6829fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 6839fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States sid = smb_sid_fromstr(sidstr); 6849fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States if (sid != NULL) { 6859fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States if (lsa_lookup_sid(sid, &ainfo) == NT_STATUS_SUCCESS) { 6869fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States sidtype = ainfo.a_type; 6879fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States smb_account_free(&ainfo); 6889fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States } 6899fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States smb_sid_free(sid); 6909fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States } 6919fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States return (sidtype); 6929fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States } 6939fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 6949fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States /* 6959fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * smb_quota_getid 6969fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * 6979fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * Get the user/group id for the sid. 6989fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States */ 6999fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States static int 7009fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States smb_quota_getid(char *sidstr, uint32_t sidtype, uint32_t *id) 7019fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States { 7029fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States int rc = 0; 7039fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States smb_sid_t *sid = NULL; 7049fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States int idtype; 7059fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 7069fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States sid = smb_sid_fromstr(sidstr); 7079fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States if (sid == NULL) 7089fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States return (-1); 7099fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 7109fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States switch (sidtype) { 7119fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States case SidTypeUser: 7129fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States idtype = SMB_IDMAP_USER; 7139fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States break; 7149fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States case SidTypeWellKnownGroup: 7159fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States case SidTypeGroup: 7169fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States case SidTypeAlias: 7179fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States idtype = SMB_IDMAP_GROUP; 7189fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States break; 7199fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States default: 7209fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States rc = -1; 7219fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States break; 7229fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States } 7239fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 7249fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States if (rc == 0) 7259fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States rc = smb_idmap_getid(sid, id, &idtype); 7269fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 7279fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States smb_sid_free(sid); 7289fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 7299fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States return (rc); 7309fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States } 7319fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 7329fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States /* 7339fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * smb_quota_tree_lookup 7349fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * 7359fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * Find the quota tree in smb_quota_fs_list. 7369fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * 7379fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * If the tree is found but is locked, waits for it to become available. 7389fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * If the tree is available, locks it and returns it. 7399fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * Otherwise, returns NULL. 7409fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States */ 7419fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States static smb_quota_tree_t * 7429fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States smb_quota_tree_lookup(const char *path) 7439fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States { 7449fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States smb_quota_tree_t *qtree = NULL; 7459fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 7469fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States assert(path); 7479fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States (void) mutex_lock(&smb_quota_list_mutex); 7489fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 7499fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States qtree = list_head(&smb_quota_fs_list); 7509fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States while (qtree != NULL) { 7519fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States if (!smb_quota_list_init || smb_quota_shutdown) { 7529fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States (void) mutex_unlock(&smb_quota_list_mutex); 7539fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States return (NULL); 7549fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States } 7559fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 7569fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States (void) mutex_lock(&qtree->qt_mutex); 7579fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States assert(qtree->qt_refcnt > 0); 7589fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 7599fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States if (!smb_quota_tree_match(qtree, path)) { 7609fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States (void) mutex_unlock(&qtree->qt_mutex); 7619fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States qtree = list_next(&smb_quota_fs_list, qtree); 7629fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States continue; 7639fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States } 7649fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 7659fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States if (qtree->qt_locked) { 7669fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States (void) mutex_unlock(&qtree->qt_mutex); 7679fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States (void) cond_wait(&smb_quota_list_condvar, 7689fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States &smb_quota_list_mutex); 7699fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States qtree = list_head(&smb_quota_fs_list); 7709fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States continue; 7719fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States } 7729fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 7739fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States ++(qtree->qt_refcnt); 7749fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States qtree->qt_locked = B_TRUE; 7759fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States (void) mutex_unlock(&qtree->qt_mutex); 7769fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States break; 7779fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States }; 7789fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 7799fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States (void) mutex_unlock(&smb_quota_list_mutex); 7809fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States return (qtree); 7819fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States } 7829fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 7839fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States /* 7849fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * smb_quota_tree_release 7859fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States */ 7869fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States static void 7879fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States smb_quota_tree_release(smb_quota_tree_t *qtree) 7889fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States { 7899fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States boolean_t delete; 7909fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 7919fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States (void) mutex_lock(&qtree->qt_mutex); 7929fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States assert(qtree->qt_locked); 7939fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States assert(qtree->qt_refcnt > 0); 7949fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 7959fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States --(qtree->qt_refcnt); 7969fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States qtree->qt_locked = B_FALSE; 7979fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States delete = (qtree->qt_refcnt == 0); 7989fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States (void) mutex_unlock(&qtree->qt_mutex); 7999fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 8009fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States (void) mutex_lock(&smb_quota_list_mutex); 8019fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States if (delete) 8029fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States smb_quota_tree_delete(qtree); 8039fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States (void) cond_broadcast(&smb_quota_list_condvar); 8049fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States (void) mutex_unlock(&smb_quota_list_mutex); 8059fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States } 8069fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 8079fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States /* 8089fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * smb_quota_tree_match 8099fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * 8109fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * Determine if qtree represents the file system identified by path 8119fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States */ 8129fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States static boolean_t 8139fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States smb_quota_tree_match(smb_quota_tree_t *qtree, const char *path) 8149fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States { 8159fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States return (strncmp(qtree->qt_path, path, MAXPATHLEN) == 0); 8169fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States } 8179fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 8189fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States /* 8199fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * smb_quota_tree_create 8209fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * 8219fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * Create and initialize an smb_quota_tree_t structure 8229fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States */ 8239fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States static smb_quota_tree_t * 8249fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States smb_quota_tree_create(const char *path) 8259fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States { 8269fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States smb_quota_tree_t *qtree; 8279fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 8289fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States assert(MUTEX_HELD(&smb_quota_list_mutex)); 8299fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 830c5866007SKeyur Desai qtree = calloc(sizeof (smb_quota_tree_t), 1); 8319fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States if (qtree == NULL) 8329fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States return (NULL); 8339fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 8349fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States qtree->qt_path = strdup(path); 8359fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States if (qtree->qt_path == NULL) { 8369fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States free(qtree); 8379fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States return (NULL); 8389fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States } 8399fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 8409fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States qtree->qt_timestamp = 0; 8419fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States qtree->qt_locked = B_FALSE; 8429fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States qtree->qt_refcnt = 1; 8439fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States qtree->qt_sharecnt = 1; 8449fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 8459fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States avl_create(&qtree->qt_avl, smb_quota_sid_cmp, 8469fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States sizeof (smb_quota_t), offsetof(smb_quota_t, q_avl_node)); 8479fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 8489fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States ++smb_quota_tree_cnt; 8499fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States return (qtree); 8509fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States } 8519fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 8529fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States /* 8539fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * smb_quota_tree_delete 8549fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * 8559fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * Free and delete the smb_quota_tree_t structure. 8569fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * qtree must have no users (refcnt == 0). 8579fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States */ 8589fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States static void 8599fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States smb_quota_tree_delete(smb_quota_tree_t *qtree) 8609fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States { 8619fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States void *cookie = NULL; 8629fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States smb_quota_t *node; 8639fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 8649fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States assert(MUTEX_HELD(&smb_quota_list_mutex)); 8659fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States assert(qtree->qt_refcnt == 0); 8669fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 8679fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States while ((node = avl_destroy_nodes(&qtree->qt_avl, &cookie)) != NULL) 8689fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States free(node); 8699fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States avl_destroy(&qtree->qt_avl); 8709fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 8719fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States free(qtree->qt_path); 8729fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States free(qtree); 8739fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 8749fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States --smb_quota_tree_cnt; 8759fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States } 8769fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 8779fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States /* 8789fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * smb_quota_sid_cmp 8799fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * 8809fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * Comparision function for nodes in an AVL tree which holds quota 8819fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * entries indexed by SID. 8829fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States */ 8839fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States static int 8849fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States smb_quota_sid_cmp(const void *l_arg, const void *r_arg) 8859fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States { 8869fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States const char *l_sid = ((smb_quota_t *)l_arg)->q_sidstr; 8879fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States const char *r_sid = ((smb_quota_t *)r_arg)->q_sidstr; 8889fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States int ret; 8899fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 8909fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States ret = strncasecmp(l_sid, r_sid, SMB_SID_STRSZ); 8919fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 8929fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States if (ret > 0) 8939fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States return (1); 8949fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States if (ret < 0) 8959fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States return (-1); 8969fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States return (0); 8979fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States } 8989fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 8999fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States /* 9009fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * smb_quota_tree_populate 9019fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * 9029fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * If the quota tree needs to be (re)populated: 9039fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * - delete the qtree's contents 9049fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * - repopulate the qtree from zfs 9059fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * - set the qtree's timestamp. 9069fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States */ 9079fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States static uint32_t 9089fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States smb_quota_tree_populate(smb_quota_tree_t *qtree) 9099fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States { 9109fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States void *cookie = NULL; 9119fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States void *node; 9129fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States uint32_t status; 9139fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 9149fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States assert(qtree->qt_locked); 9159fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 9169fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States if (!smb_quota_tree_expired(qtree)) 9179fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States return (NT_STATUS_SUCCESS); 9189fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 9199fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States while ((node = avl_destroy_nodes(&qtree->qt_avl, &cookie)) != NULL) 9209fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States free(node); 9219fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 9229fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States status = smb_quota_zfs_get_quotas(qtree); 9239fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States if (status != NT_STATUS_SUCCESS) 9249fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States return (status); 9259fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 9269fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States qtree->qt_timestamp = time(NULL); 9279fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 9289fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States return (NT_STATUS_SUCCESS); 9299fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States } 9309fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 9319fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States static boolean_t 9329fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States smb_quota_tree_expired(smb_quota_tree_t *qtree) 9339fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States { 9349fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States time_t tnow = time(NULL); 9359fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States return ((tnow - qtree->qt_timestamp) > SMB_QUOTA_REFRESH); 9369fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States } 9379fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 9389fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States static void 9399fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States smb_quota_tree_set_expired(smb_quota_tree_t *qtree) 9409fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States { 9419fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States qtree->qt_timestamp = 0; 9429fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States } 9439fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 9449fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States /* 9459fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * smb_quota_zfs_get_quotas 9469fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * 9479fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * Get user and group quotas from ZFS and use them to 9489fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * populate the quota tree. 9499fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States */ 9509fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States static uint32_t 9519fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States smb_quota_zfs_get_quotas(smb_quota_tree_t *qtree) 9529fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States { 9539fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States smb_quota_zfs_handle_t zfs_hdl; 9549fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States smb_quota_zfs_arg_t arg; 9559fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States zfs_userquota_prop_t p; 9569fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States uint32_t status = NT_STATUS_SUCCESS; 9579fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 9589fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States status = smb_quota_zfs_init(qtree->qt_path, &zfs_hdl); 9599fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States if (status != NT_STATUS_SUCCESS) 9609fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States return (status); 9619fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 9629fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States arg.qa_avl = &qtree->qt_avl; 9639fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States for (p = 0; p < ZFS_NUM_USERQUOTA_PROPS; p++) { 9649fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States arg.qa_prop = p; 9659fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States if (zfs_userspace(zfs_hdl.z_fs, p, 9669fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States smb_quota_zfs_callback, &arg) != 0) { 9679fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States status = NT_STATUS_INTERNAL_ERROR; 9689fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States break; 9699fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States } 9709fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States } 9719fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 9729fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States smb_quota_zfs_fini(&zfs_hdl); 9739fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States return (status); 9749fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States } 9759fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 9769fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States /* 9779fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * smb_quota_zfs_callback 9789fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * 9799fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * Find or create a node in the avl tree (arg->qa_avl) that matches 9809fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * the SID derived from domain and rid. If no domain is specified, 9819fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * lookup the sid (smb_quota_sidstr()). 9829fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * Populate the node. 9839fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * The property type (arg->qa_prop) determines which property 'space' 9849fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * refers to. 9859fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States */ 9869fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States static int 9879fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States smb_quota_zfs_callback(void *arg, const char *domain, uid_t rid, uint64_t space) 9889fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States { 9899fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States smb_quota_zfs_arg_t *qarg = (smb_quota_zfs_arg_t *)arg; 9909fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States zfs_userquota_prop_t qprop = qarg->qa_prop; 9919fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States avl_tree_t *avl_tree = qarg->qa_avl; 9929fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States avl_index_t where; 9939fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States smb_quota_t *quota, key; 9949fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 9959fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States if (domain == NULL || domain[0] == '\0') { 9969fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States if (smb_quota_sidstr(rid, qprop, key.q_sidstr) != 0) 9979fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States return (0); 9989fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States } else { 9999fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States (void) snprintf(key.q_sidstr, SMB_SID_STRSZ, "%s-%u", 10009fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States domain, (uint32_t)rid); 10019fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States } 10029fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 10039fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States quota = avl_find(avl_tree, &key, &where); 10049fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States if (quota == NULL) { 10059fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States quota = malloc(sizeof (smb_quota_t)); 10069fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States if (quota == NULL) 10079fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States return (NT_STATUS_NO_MEMORY); 10089fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States bzero(quota, sizeof (smb_quota_t)); 10099fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States quota->q_thresh = SMB_QUOTA_UNLIMITED; 10109fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States quota->q_limit = SMB_QUOTA_UNLIMITED; 10119fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States avl_insert(avl_tree, (void *)quota, where); 10129fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States (void) strlcpy(quota->q_sidstr, key.q_sidstr, SMB_SID_STRSZ); 10139fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States } 10149fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 10159fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States switch (qprop) { 10169fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States case ZFS_PROP_USERUSED: 10179fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States quota->q_sidtype = SidTypeUser; 10189fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States quota->q_used = space; 10199fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States break; 10209fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States case ZFS_PROP_GROUPUSED: 10219fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States quota->q_sidtype = SidTypeGroup; 10229fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States quota->q_used = space; 10239fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States break; 10249fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States case ZFS_PROP_USERQUOTA: 10259fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States quota->q_sidtype = SidTypeUser; 10269fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States quota->q_limit = space; 10279fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States break; 10289fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States case ZFS_PROP_GROUPQUOTA: 10299fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States quota->q_sidtype = SidTypeGroup; 10309fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States quota->q_limit = space; 10319fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States break; 10329fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States default: 10339fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States break; 10349fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States } 10359fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 10369fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States quota->q_thresh = quota->q_limit; 10379fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 10389fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States return (0); 10399fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States } 10409fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 10419fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States /* 10429fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * smb_quota_sidstr 10439fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * 10449fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * Use idmap to get the sid for the specified id and return 10459fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * the string version of the sid in sidstr. 10469fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * sidstr must be a buffer of at least SMB_SID_STRSZ. 10479fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States */ 10489fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States static int 10499fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States smb_quota_sidstr(uint32_t id, zfs_userquota_prop_t qprop, char *sidstr) 10509fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States { 10519fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States int idtype; 10529fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States smb_sid_t *sid; 10539fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 10549fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States switch (qprop) { 10559fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States case ZFS_PROP_USERUSED: 10569fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States case ZFS_PROP_USERQUOTA: 10579fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States idtype = SMB_IDMAP_USER; 10589fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States break; 10599fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States case ZFS_PROP_GROUPUSED: 10609fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States case ZFS_PROP_GROUPQUOTA: 10619fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States idtype = SMB_IDMAP_GROUP; 10629fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States break; 10639fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States default: 10649fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States return (-1); 10659fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States } 10669fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 10679fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States if (smb_idmap_getsid(id, idtype, &sid) != IDMAP_SUCCESS) 10689fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States return (-1); 10699fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 10709fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States smb_sid_tostr(sid, sidstr); 10719fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States smb_sid_free(sid); 10729fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 10739fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States return (0); 10749fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States } 10759fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 10769fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States /* 10779fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * smb_quota_zfs_init 10789fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * 10799fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * Initialize zfs library and dataset handles 10809fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States */ 10819fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States static uint32_t 10829fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States smb_quota_zfs_init(const char *path, smb_quota_zfs_handle_t *zfs_hdl) 10839fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States { 10849fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States char dataset[MAXPATHLEN]; 10859fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 10869fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States if (smb_getdataset(path, dataset, MAXPATHLEN) != 0) 10879fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States return (NT_STATUS_INVALID_PARAMETER); 10889fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 10899fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States if ((zfs_hdl->z_lib = libzfs_init()) == NULL) 10909fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States return (NT_STATUS_INTERNAL_ERROR); 10919fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 10929fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States zfs_hdl->z_fs = zfs_open(zfs_hdl->z_lib, dataset, ZFS_TYPE_DATASET); 10939fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States if (zfs_hdl->z_fs == NULL) { 10949fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States libzfs_fini(zfs_hdl->z_lib); 10959fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States return (NT_STATUS_ACCESS_DENIED); 10969fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States } 10979fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 10989fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States return (NT_STATUS_SUCCESS); 10999fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States } 11009fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 11019fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States /* 11029fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * smb_quota_zfs_fini 11039fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * 11049fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * Close zfs library and dataset handles 11059fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States */ 11069fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States static void 11079fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States smb_quota_zfs_fini(smb_quota_zfs_handle_t *zfs_hdl) 11089fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States { 11099fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States zfs_close(zfs_hdl->z_fs); 11109fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States libzfs_fini(zfs_hdl->z_lib); 11119fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States } 11129fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 11139fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States /* 11149fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * smb_quota_add_ctrldir 11159fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * 11169fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * In order to display the quota properties tab, windows clients 11179fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * check for the existence of the quota control file, created 11189fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * here as follows: 11199fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * - Create SMB_QUOTA_CNTRL_DIR directory (with A_HIDDEN & A_SYSTEM 11209fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * attributes). 11219fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * - Create the SMB_QUOTA_CNTRL_FILE file (with extended attribute 11229fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * SMB_QUOTA_CNTRL_INDEX_XATTR) in the SMB_QUOTA_CNTRL_DIR directory. 11239fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * - Set the acl of SMB_QUOTA_CNTRL_FILE file to SMB_QUOTA_CNTRL_PERM. 11249fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States */ 11259fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States static void 11269fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States smb_quota_add_ctrldir(const char *path) 11279fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States { 11289fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States int newfd, dirfd, afd; 112929e6af5cSAlek Pinchuk nvlist_t *attr; 113029e6af5cSAlek Pinchuk char dir[MAXPATHLEN], file[MAXPATHLEN], *acl_text; 113129e6af5cSAlek Pinchuk acl_t *aclp, *existing_aclp; 113229e6af5cSAlek Pinchuk boolean_t qdir_created, prop_hidden = B_FALSE, prop_sys = B_FALSE; 11339fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States struct stat statbuf; 11349fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 11359fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States assert(path != NULL); 11369fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 11379fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States (void) snprintf(dir, MAXPATHLEN, ".%s/%s", path, SMB_QUOTA_CNTRL_DIR); 11389fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States (void) snprintf(file, MAXPATHLEN, "%s/%s", dir, SMB_QUOTA_CNTRL_FILE); 11399fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States if ((mkdir(dir, 0750) < 0) && (errno != EEXIST)) 11409fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States return; 114129e6af5cSAlek Pinchuk qdir_created = (errno == EEXIST) ? B_FALSE : B_TRUE; 11429fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 11439fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States if ((dirfd = open(dir, O_RDONLY)) < 0) { 114429e6af5cSAlek Pinchuk if (qdir_created) 11459fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States (void) remove(dir); 11469fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States return; 11479fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States } 11489fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 114929e6af5cSAlek Pinchuk if (fgetattr(dirfd, XATTR_VIEW_READWRITE, &attr) != 0) { 11509fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States (void) close(dirfd); 115129e6af5cSAlek Pinchuk if (qdir_created) 115229e6af5cSAlek Pinchuk (void) remove(dir); 115329e6af5cSAlek Pinchuk return; 115429e6af5cSAlek Pinchuk } 115529e6af5cSAlek Pinchuk 115629e6af5cSAlek Pinchuk if ((nvlist_lookup_boolean_value(attr, A_HIDDEN, &prop_hidden) != 0) || 115729e6af5cSAlek Pinchuk (nvlist_lookup_boolean_value(attr, A_SYSTEM, &prop_sys) != 0)) { 115829e6af5cSAlek Pinchuk nvlist_free(attr); 115929e6af5cSAlek Pinchuk (void) close(dirfd); 116029e6af5cSAlek Pinchuk if (qdir_created) 116129e6af5cSAlek Pinchuk (void) remove(dir); 116229e6af5cSAlek Pinchuk return; 116329e6af5cSAlek Pinchuk } 116429e6af5cSAlek Pinchuk nvlist_free(attr); 116529e6af5cSAlek Pinchuk 116629e6af5cSAlek Pinchuk /* 116729e6af5cSAlek Pinchuk * Before setting attr or acl we check if the they have already been 116829e6af5cSAlek Pinchuk * set to what we want. If so we could be dealing with a received 116929e6af5cSAlek Pinchuk * snapshot and setting these is not needed. 117029e6af5cSAlek Pinchuk */ 117129e6af5cSAlek Pinchuk 117229e6af5cSAlek Pinchuk if (!prop_hidden || !prop_sys) { 117329e6af5cSAlek Pinchuk if (nvlist_alloc(&attr, NV_UNIQUE_NAME, 0) == 0) { 117429e6af5cSAlek Pinchuk if ((nvlist_add_boolean_value( 117529e6af5cSAlek Pinchuk attr, A_HIDDEN, 1) != 0) || 1176*a90cf9f2SGordon Ross (nvlist_add_boolean_value( 1177*a90cf9f2SGordon Ross attr, A_SYSTEM, 1) != 0) || 1178*a90cf9f2SGordon Ross (fsetattr(dirfd, XATTR_VIEW_READWRITE, attr))) { 117929e6af5cSAlek Pinchuk nvlist_free(attr); 118029e6af5cSAlek Pinchuk (void) close(dirfd); 118129e6af5cSAlek Pinchuk if (qdir_created) 11829fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States (void) remove(dir); 11839fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States return; 11849fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States } 11859fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States } 118629e6af5cSAlek Pinchuk nvlist_free(attr); 118729e6af5cSAlek Pinchuk } 118829e6af5cSAlek Pinchuk 11899fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States (void) close(dirfd); 11909fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 11919fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States if (stat(file, &statbuf) != 0) { 11929fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States if ((newfd = creat(file, 0640)) < 0) { 119329e6af5cSAlek Pinchuk if (qdir_created) 11949fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States (void) remove(dir); 11959fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States return; 11969fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States } 11979fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States (void) close(newfd); 11989fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States } 11999fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 12009fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States afd = attropen(file, SMB_QUOTA_CNTRL_INDEX_XATTR, O_RDWR | O_CREAT, 12019fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 0640); 12029fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States if (afd == -1) { 12039fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States (void) unlink(file); 120429e6af5cSAlek Pinchuk if (qdir_created) 12059fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States (void) remove(dir); 12069fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States return; 12079fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States } 12089fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States (void) close(afd); 12099fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 121029e6af5cSAlek Pinchuk if (acl_get(file, 0, &existing_aclp) == -1) { 12119fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States (void) unlink(file); 121229e6af5cSAlek Pinchuk if (qdir_created) 12139fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States (void) remove(dir); 12149fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States return; 12159fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States } 12169fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 121729e6af5cSAlek Pinchuk acl_text = acl_totext(existing_aclp, ACL_COMPACT_FMT); 121829e6af5cSAlek Pinchuk acl_free(existing_aclp); 121929e6af5cSAlek Pinchuk if (acl_text == NULL) { 12209fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States (void) unlink(file); 122129e6af5cSAlek Pinchuk if (qdir_created) 122229e6af5cSAlek Pinchuk (void) remove(dir); 122329e6af5cSAlek Pinchuk return; 122429e6af5cSAlek Pinchuk } 122529e6af5cSAlek Pinchuk 1226*a90cf9f2SGordon Ross aclp = NULL; 122729e6af5cSAlek Pinchuk if (strcmp(acl_text, SMB_QUOTA_CNTRL_PERM) != 0) { 122829e6af5cSAlek Pinchuk if (acl_fromtext(SMB_QUOTA_CNTRL_PERM, &aclp) != 0) { 122929e6af5cSAlek Pinchuk free(acl_text); 123029e6af5cSAlek Pinchuk (void) unlink(file); 123129e6af5cSAlek Pinchuk if (qdir_created) 123229e6af5cSAlek Pinchuk (void) remove(dir); 123329e6af5cSAlek Pinchuk return; 123429e6af5cSAlek Pinchuk } 123529e6af5cSAlek Pinchuk if (acl_set(file, aclp) == -1) { 123629e6af5cSAlek Pinchuk free(acl_text); 123729e6af5cSAlek Pinchuk (void) unlink(file); 123829e6af5cSAlek Pinchuk if (qdir_created) 12399fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States (void) remove(dir); 12409fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States acl_free(aclp); 12419fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States return; 12429fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States } 1243*a90cf9f2SGordon Ross acl_free(aclp); 124429e6af5cSAlek Pinchuk } 124529e6af5cSAlek Pinchuk free(acl_text); 12469fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States } 12479fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 12489fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States /* 12499fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * smb_quota_remove_ctrldir 12509fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * 12519fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * Remove SMB_QUOTA_CNTRL_FILE and SMB_QUOTA_CNTRL_DIR. 12529fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States */ 12539fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States static void 12549fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States smb_quota_remove_ctrldir(const char *path) 12559fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States { 12569fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States char dir[MAXPATHLEN], file[MAXPATHLEN]; 12579fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States assert(path); 12589fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 12599fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States (void) snprintf(dir, MAXPATHLEN, ".%s/%s", path, SMB_QUOTA_CNTRL_DIR); 12609fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States (void) snprintf(file, MAXPATHLEN, "%s/%s", dir, SMB_QUOTA_CNTRL_FILE); 12619fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States (void) unlink(file); 12629fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States (void) remove(dir); 12639fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States } 1264