nfs-ganesha 1.4

fsal_quota.c

Go to the documentation of this file.
00001 /*
00002  * vim:expandtab:shiftwidth=8:tabstop=8:
00003  *
00004  * Copyright CEA/DAM/DIF  (2008)
00005  * contributeur : Philippe DENIEL   philippe.deniel@cea.fr
00006  *
00007  *
00008  * This program is free software; you can redistribute it and/or
00009  * modify it under the terms of the GNU Lesser General Public
00010  * License as published by the Free Software Foundation; either
00011  * version 3 of the License, or (at your option) any later version.
00012  *
00013  * This program is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016  * Lesser General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU Lesser General Public
00019  * License along with this library; if not, write to the Free Software
00020  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00021  *
00022  * ------------- 
00023  */
00024 
00030 #ifdef HAVE_CONFIG_H
00031 #include "config.h"
00032 #endif
00033 
00034 #include "fsal.h"
00035 #include "fsal_internal.h"
00036 #include "fsal_convert.h"
00037 
00038 /* For llapi_quotactl */
00039 #include <lustre/liblustreapi.h>
00040 #include <lustre/lustre_user.h>
00041 #include <linux/quota.h>
00042 
00043 #ifndef QUOTABLOCK_SIZE
00044 #define QUOTABLOCK_SIZE (1 << 10)
00045 #endif
00046 
00063 fsal_status_t LUSTREFSAL_check_quota( char              * path,  /* IN */
00064                                       fsal_quota_type_t   quota_type,
00065                                       fsal_uid_t          fsal_uid)      /* IN */
00066 {
00067   struct if_quotactl dataquota ;
00068 
00069   if(!path )
00070     ReturnCode(ERR_FSAL_FAULT, 0);
00071 
00072   if( fsal_uid == 0 ) /* No quota for root */
00073     ReturnCode(ERR_FSAL_NO_ERROR, 0) ;
00074 
00075   memset((char *)&dataquota, 0, sizeof(struct if_quotactl));
00076 
00077   dataquota.qc_cmd  = LUSTRE_Q_GETQUOTA ;
00078   dataquota.qc_type = quota_type ; // UGQUOTA ??
00079   dataquota.qc_id = fsal_uid ;
00080 
00081   if(llapi_quotactl( path, &dataquota) < 0 )
00082     ReturnCode(posix2fsal_error(errno), errno);
00083 
00084   /* If dqb_bhardlimit is no-zero, then quota are set for this user */
00085   if(  dataquota.qc_dqblk.dqb_bhardlimit != 0 )
00086     if( dataquota.qc_dqblk.dqb_curspace > dataquota.qc_dqblk.dqb_bhardlimit  )
00087         ReturnCode( ERR_FSAL_DQUOT, EDQUOT ) ;
00088 
00089 
00090   ReturnCode(ERR_FSAL_NO_ERROR, 0) ;
00091 } /* LUSTREFSAL_check_quota */
00092               
00113 fsal_status_t LUSTREFSAL_set_quota(fsal_path_t * pfsal_path,       /* IN */
00114                                 int quota_type, /* IN */
00115                                 fsal_uid_t fsal_uid,    /* IN */
00116                                 fsal_quota_t * pquota,  /* IN */
00117                                 fsal_quota_t * presquota)       /* OUT */
00118 {
00119   fsal_status_t fsal_status;
00120   struct if_quotactl dataquota ;
00121 
00122   memset((char *)&dataquota, 0, sizeof(struct if_quotactl));
00123 
00124   dataquota.qc_cmd  = LUSTRE_Q_GETQUOTA ;
00125   dataquota.qc_type = quota_type ; 
00126   dataquota.qc_id = fsal_uid ;
00127 
00128   if(!pfsal_path || !pfsal_path->path ||!pquota)
00129     ReturnCode(ERR_FSAL_FAULT, 0);
00130 
00131   memset((char *)&dataquota, 0, sizeof(struct if_quotactl));
00132 
00133   /* Convert FSAL structure to XFS one */
00134   if(pquota->bhardlimit != 0)
00135     {
00136       dataquota.qc_dqblk.dqb_bhardlimit = pquota->bhardlimit;
00137       dataquota.qc_dqblk.dqb_valid |= QIF_BLIMITS;
00138     }
00139 
00140   if(pquota->bsoftlimit != 0)
00141     {
00142       dataquota.qc_dqblk.dqb_bsoftlimit = pquota->bsoftlimit;
00143       dataquota.qc_dqblk.dqb_valid |= QIF_BLIMITS;
00144     }
00145 
00146   if(pquota->fhardlimit != 0)
00147     {
00148       dataquota.qc_dqblk.dqb_ihardlimit = pquota->fhardlimit;
00149       dataquota.qc_dqblk.dqb_valid |= QIF_ILIMITS;
00150     }
00151 
00152   if(pquota->btimeleft != 0)
00153     {
00154       dataquota.qc_dqblk.dqb_btime = pquota->btimeleft;
00155       dataquota.qc_dqblk.dqb_valid |= QIF_BTIME;
00156     }
00157 
00158   if(pquota->ftimeleft != 0)
00159     {
00160       dataquota.qc_dqblk.dqb_itime = pquota->ftimeleft;
00161       dataquota.qc_dqblk.dqb_valid |= QIF_ITIME;
00162     }
00163 
00164   if(llapi_quotactl( pfsal_path->path, &dataquota) < 0 )
00165     ReturnCode(posix2fsal_error(errno), errno);
00166 
00167   if(presquota != NULL)
00168     {
00169       fsal_status = FSAL_get_quota(pfsal_path, quota_type, fsal_uid, presquota);
00170 
00171       if(FSAL_IS_ERROR(fsal_status))
00172         return fsal_status;
00173     }
00174 
00175   ReturnCode(ERR_FSAL_NO_ERROR, 0);
00176 }                               /*  FSAL_set_quota */ 
00177 
00195 fsal_status_t LUSTREFSAL_get_quota(fsal_path_t * pfsal_path,       /* IN */
00196                                    int quota_type, /* IN */
00197                                    fsal_uid_t fsal_uid,    /* IN */
00198                                    fsal_quota_t * pquota)  /* OUT */
00199 {
00200   struct if_quotactl dataquota ;
00201 
00202   memset((char *)&dataquota, 0, sizeof(struct if_quotactl));
00203 
00204   if(!pfsal_path || !pfsal_path->path ||!pquota)
00205     ReturnCode(ERR_FSAL_FAULT, 0);
00206 
00207   dataquota.qc_cmd  = LUSTRE_Q_GETQUOTA ;
00208   dataquota.qc_type = quota_type ; 
00209   dataquota.qc_id = fsal_uid ;
00210 
00211   if(llapi_quotactl( pfsal_path->path, &dataquota) < 0 )
00212     ReturnCode(posix2fsal_error(errno), errno);
00213 
00214   /* Convert XFS structure to FSAL one */
00215   pquota->bsize      = 1024; // LUSTRE has block of 1024 bytes
00216 
00217   pquota->bhardlimit = dataquota.qc_dqblk.dqb_bhardlimit ;
00218   pquota->bsoftlimit = dataquota.qc_dqblk.dqb_bsoftlimit ;
00219   pquota->curblocks  = dataquota.qc_dqblk.dqb_curspace /  pquota->bsize  ;
00220 
00221   pquota->fhardlimit = dataquota.qc_dqblk.dqb_ihardlimit;
00222   pquota->fsoftlimit = dataquota.qc_dqblk.dqb_isoftlimit;
00223   pquota->curfiles   = dataquota.qc_dqblk.dqb_curinodes;
00224 
00225   /* Times left are set only if used resource is in-between soft and hard limits */
00226   if( ( pquota->curfiles >  pquota->fsoftlimit ) && ( pquota->curfiles <  pquota->fhardlimit ) )
00227      pquota->ftimeleft  = dataquota.qc_dqblk.dqb_itime;
00228   else
00229      pquota->ftimeleft = 0 ;
00230 
00231   if( ( pquota->curblocks >  pquota->bsoftlimit ) && ( pquota->curblocks <  pquota->bhardlimit ) )
00232      pquota->btimeleft  = dataquota.qc_dqblk.dqb_btime;
00233   else
00234      pquota->btimeleft = 0 ;
00235 
00236   ReturnCode(ERR_FSAL_NO_ERROR, 0);
00237 }                               /*  FSAL_get_quota */
00238 
00239