Whamcloud - gitweb
LU-847 quota: client retrieve quota usage directly
[fs/lustre-release.git] / lustre / llite / dir.c
index 4a8fc75..dcd4331 100644 (file)
@@ -513,7 +513,6 @@ int ll_readdir(struct file *filp, void *cookie, filldir_t filldir)
         struct page          *page;
         struct ll_dir_chain   chain;
         int                   done;
-        int                   shift;
         int                   rc;
         ENTRY;
 
@@ -529,7 +528,6 @@ int ll_readdir(struct file *filp, void *cookie, filldir_t filldir)
 
         rc    = 0;
         done  = 0;
-        shift = 0;
         ll_dir_chain_init(&chain);
 
         fd->fd_dir.lfd_next = pos;
@@ -798,8 +796,8 @@ int ll_dir_getstripe(struct inode *inode, struct lov_mds_md **lmmp,
         op_data = ll_prep_md_op_data(NULL, inode, NULL, NULL,
                                      0, lmmsize, LUSTRE_OPC_ANY,
                                      NULL);
-        if (op_data == NULL)
-                RETURN(-ENOMEM);
+        if (IS_ERR(op_data))
+                RETURN(PTR_ERR(op_data));
 
         op_data->op_valid = OBD_MD_FLEASIZE | OBD_MD_FLDIREA;
         rc = md_getattr(sbi->ll_md_exp, op_data, &req);
@@ -863,8 +861,8 @@ int ll_get_mdt_idx(struct inode *inode)
 
         op_data = ll_prep_md_op_data(NULL, inode, NULL, NULL, 0,
                                      0, LUSTRE_OPC_ANY, NULL);
-        if (op_data == NULL)
-                RETURN(-ENOMEM);
+        if (IS_ERR(op_data))
+                RETURN(PTR_ERR(op_data));
 
         op_data->op_valid |= OBD_MD_MDTIDX;
         rc = md_getattr(sbi->ll_md_exp, op_data, NULL);
@@ -982,7 +980,47 @@ static int quotactl_ioctl(struct ll_sb_info *sbi, struct if_quotactl *qctl)
                         OBD_FREE_PTR(oqctl);
                         RETURN(rc);
                 }
+                /* If QIF_SPACE is not set, client should collect the
+                 * space usage from OSSs by itself */
+                if (cmd == Q_GETQUOTA &&
+                    !(oqctl->qc_dqblk.dqb_valid & QIF_SPACE) &&
+                    !oqctl->qc_dqblk.dqb_curspace) {
+                        struct obd_quotactl *oqctl_tmp;
+
+                        OBD_ALLOC_PTR(oqctl_tmp);
+                        if (oqctl_tmp == NULL)
+                                GOTO(out, rc = -ENOMEM);
+
+                        oqctl_tmp->qc_cmd = Q_GETOQUOTA;
+                        oqctl_tmp->qc_id = oqctl->qc_id;
+                        oqctl_tmp->qc_type = oqctl->qc_type;
+
+                        /* collect space usage from OSTs */
+                        oqctl_tmp->qc_dqblk.dqb_curspace = 0;
+                        rc = obd_quotactl(sbi->ll_dt_exp, oqctl_tmp);
+                        if (!rc || rc == -EREMOTEIO) {
+                                oqctl->qc_dqblk.dqb_curspace =
+                                        oqctl_tmp->qc_dqblk.dqb_curspace;
+                                oqctl->qc_dqblk.dqb_valid |= QIF_SPACE;
+                        }
 
+                        /* collect space & inode usage from MDTs */
+                        oqctl_tmp->qc_dqblk.dqb_curspace = 0;
+                        oqctl_tmp->qc_dqblk.dqb_curinodes = 0;
+                        rc = obd_quotactl(sbi->ll_md_exp, oqctl_tmp);
+                        if (!rc || rc == -EREMOTEIO) {
+                                oqctl->qc_dqblk.dqb_curspace +=
+                                        oqctl_tmp->qc_dqblk.dqb_curspace;
+                                oqctl->qc_dqblk.dqb_curinodes =
+                                        oqctl_tmp->qc_dqblk.dqb_curinodes;
+                                oqctl->qc_dqblk.dqb_valid |= QIF_INODES;
+                        } else {
+                                oqctl->qc_dqblk.dqb_valid &= ~QIF_SPACE;
+                        }
+
+                        OBD_FREE_PTR(oqctl_tmp);
+                }
+out:
                 QCTL_COPY(qctl, oqctl);
                 OBD_FREE_PTR(oqctl);
         }
@@ -1053,8 +1091,8 @@ static int ll_dir_ioctl(struct inode *inode, struct file *file,
 
                 op_data = ll_prep_md_op_data(NULL, inode, NULL, filename, namelen,
                                              0, LUSTRE_OPC_ANY, NULL);
-                if (op_data == NULL)
-                        GOTO(out_free, rc = -ENOMEM);
+                if (IS_ERR(op_data))
+                        GOTO(out_free, rc = PTR_ERR(op_data));
 
                 op_data->op_valid = OBD_MD_FLID;
                 rc = md_getattr_name(sbi->ll_md_exp, op_data, &request);