nfs-ganesha 1.4
|
00001 /* 00002 * Copyright CEA/DAM/DIF 2010 00003 * Author: Philippe Deniel (philippe.deniel@cea.fr) 00004 * 00005 * -------------------------- 00006 * 00007 * This program is free software; you can redistribute it and/or 00008 * modify it under the terms of the GNU Lesser General Public 00009 * License as published by the Free Software Foundation; either 00010 * version 3 of the License, or (at your option) any later version. 00011 * 00012 * This program is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 * Lesser General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU Lesser General Public 00018 * License along with this library; if not, write to the Free Software 00019 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00020 * 00021 * 00022 */ 00023 00024 #ifdef HAVE_CONFIG_H 00025 #include "config.h" 00026 #endif 00027 00028 #ifdef _SOLARIS 00029 #include "solaris_port.h" 00030 #endif 00031 00032 #include <stdio.h> 00033 #include <string.h> 00034 #include <pthread.h> 00035 #include <fcntl.h> 00036 #include <sys/file.h> /* for having FNDELAY */ 00037 #include <sys/quota.h> /* For USRQUOTA */ 00038 #include "HashData.h" 00039 #include "HashTable.h" 00040 #include "log.h" 00041 #include "ganesha_rpc.h" 00042 #include "nfs23.h" 00043 #include "nfs4.h" 00044 #include "nfs_core.h" 00045 #include "cache_inode.h" 00046 #include "nfs_exports.h" 00047 #include "nfs_creds.h" 00048 #include "nfs_tools.h" 00049 #include "mount.h" 00050 #include "rquota.h" 00051 #include "nfs_proto_functions.h" 00052 00066 int rquota_setquota(nfs_arg_t *parg, 00067 exportlist_t *pexport, 00068 fsal_op_context_t *pcontext, 00069 nfs_worker_data_t *pworker, 00070 struct svc_req *preq, 00071 nfs_res_t * pres) 00072 { 00073 fsal_status_t fsal_status; 00074 fsal_quota_t fsal_quota_in; 00075 fsal_quota_t fsal_quota_out; 00076 fsal_path_t fsal_path; 00077 int quota_type = USRQUOTA; 00078 int quota_id; 00079 char work[MAXPATHLEN]; 00080 00081 LogFullDebug(COMPONENT_NFSPROTO, 00082 "REQUEST PROCESSING: Calling rquota_setquota"); 00083 00084 if(preq->rq_vers == EXT_RQUOTAVERS) 00085 { 00086 quota_type = parg->arg_ext_rquota_getquota.gqa_type; 00087 quota_id = parg->arg_ext_rquota_getquota.gqa_id; 00088 } 00089 else 00090 { 00091 quota_type = USRQUOTA; 00092 quota_id = parg->arg_rquota_getquota.gqa_uid; 00093 } 00094 00095 if(parg->arg_rquota_getquota.gqa_pathp[0] == '/') 00096 strncpy(work, parg->arg_rquota_getquota.gqa_pathp, MAXPATHLEN); 00097 else 00098 { 00099 if(nfs_export_tag2path(nfs_param.pexportlist, 00100 parg->arg_rquota_getquota.gqa_pathp, 00101 strnlen(parg->arg_rquota_getquota.gqa_pathp, MAXPATHLEN), 00102 work, MAXPATHLEN) == -1) 00103 00104 { 00105 pres->res_rquota_getquota.status = Q_EPERM; 00106 return NFS_REQ_OK; 00107 } 00108 } 00109 00110 if(FSAL_IS_ERROR((fsal_status = FSAL_str2path(work, MAXPATHLEN, &fsal_path)))) 00111 { 00112 pres->res_rquota_setquota.status = Q_EPERM; 00113 return NFS_REQ_OK; 00114 } 00115 00116 memset((char *)&fsal_quota_in, 0, sizeof(fsal_quota_t)); 00117 memset((char *)&fsal_quota_out, 0, sizeof(fsal_quota_t)); 00118 00119 fsal_quota_in.bhardlimit = parg->arg_rquota_setquota.sqa_dqblk.rq_bhardlimit; 00120 fsal_quota_in.bsoftlimit = parg->arg_rquota_setquota.sqa_dqblk.rq_bsoftlimit; 00121 fsal_quota_in.curblocks = parg->arg_rquota_setquota.sqa_dqblk.rq_curblocks; 00122 fsal_quota_in.fhardlimit = parg->arg_rquota_setquota.sqa_dqblk.rq_fhardlimit; 00123 fsal_quota_in.fsoftlimit = parg->arg_rquota_setquota.sqa_dqblk.rq_fsoftlimit; 00124 fsal_quota_in.btimeleft = parg->arg_rquota_setquota.sqa_dqblk.rq_btimeleft; 00125 fsal_quota_in.ftimeleft = parg->arg_rquota_setquota.sqa_dqblk.rq_ftimeleft; 00126 00127 fsal_status = FSAL_set_quota(&fsal_path, 00128 quota_type, quota_id, &fsal_quota_in, &fsal_quota_out); 00129 if(FSAL_IS_ERROR(fsal_status)) 00130 { 00131 if(fsal_status.major == ERR_FSAL_NO_QUOTA) 00132 pres->res_rquota_setquota.status = Q_NOQUOTA; 00133 else 00134 pres->res_rquota_setquota.status = Q_EPERM; 00135 return NFS_REQ_OK; 00136 } 00137 00138 /* is success */ 00139 pres->res_rquota_getquota.status = Q_OK; 00140 00141 pres->res_rquota_setquota.setquota_rslt_u.sqr_rquota.rq_active = TRUE; 00142 pres->res_rquota_setquota.setquota_rslt_u.sqr_rquota.rq_bhardlimit = 00143 fsal_quota_out.bhardlimit; 00144 pres->res_rquota_setquota.setquota_rslt_u.sqr_rquota.rq_bsoftlimit = 00145 fsal_quota_out.bsoftlimit; 00146 pres->res_rquota_setquota.setquota_rslt_u.sqr_rquota.rq_curblocks = 00147 fsal_quota_out.curblocks; 00148 pres->res_rquota_setquota.setquota_rslt_u.sqr_rquota.rq_fhardlimit = 00149 fsal_quota_out.fhardlimit; 00150 pres->res_rquota_setquota.setquota_rslt_u.sqr_rquota.rq_fsoftlimit = 00151 fsal_quota_out.fsoftlimit; 00152 pres->res_rquota_setquota.setquota_rslt_u.sqr_rquota.rq_btimeleft = 00153 fsal_quota_out.btimeleft; 00154 pres->res_rquota_setquota.setquota_rslt_u.sqr_rquota.rq_ftimeleft = 00155 fsal_quota_out.ftimeleft; 00156 00157 return NFS_REQ_OK; 00158 00159 return 0; 00160 } /* rquota_setquota */ 00161 00170 void rquota_setquota_Free(nfs_res_t * pres) 00171 { 00172 return; 00173 }