Whamcloud - gitweb
Bug #357, no more gratituous new line..., or typecasting
[fs/lustre-release.git] / lustre / mds / mds_lov.c
index 1be342a..9d49de1 100644 (file)
 #include <linux/module.h>
 #include <linux/lustre_mds.h>
 #include <linux/lustre_idl.h>
+#include <linux/obd_class.h>
 #include <linux/obd_lov.h>
+#include <linux/lustre_lib.h>
 
-int mds_configure_lov(struct obd_device *obd, struct lov_desc *desc,
-                      uuid_t *uuidarray)
+int mds_set_lovdesc(struct obd_device *obd, struct lov_desc *desc,
+                    obd_uuid_t *uuidarray)
 {
         struct mds_obd *mds = &obd->u.mds;
         struct obd_run_ctxt saved;
@@ -35,7 +37,7 @@ int mds_configure_lov(struct obd_device *obd, struct lov_desc *desc,
         tgt_count = desc->ld_tgt_count;
         lov_packdesc(desc);
 
-        push_ctxt(&saved, &mds->mds_ctxt);
+        push_ctxt(&saved, &mds->mds_ctxt, NULL);
         f = filp_open("LOVDESC", O_CREAT|O_RDWR, 0644);
         if (IS_ERR(f)) {
                 CERROR("Cannot open/create LOVDESC file\n");
@@ -66,7 +68,8 @@ int mds_configure_lov(struct obd_device *obd, struct lov_desc *desc,
                         if (rc >= 0)
                                 rc = -EIO;
                         break;
-                }
+                } else
+                        rc = 0;
         }
         if (filp_close(f, 0))
                 CERROR("Error closing LOVTGTS file\n");
@@ -76,14 +79,13 @@ out:
         RETURN(rc);
 }
 
-int mds_get_lovdesc(struct obd_device *obd, struct lov_desc *desc)
+int mds_get_lovdesc(struct mds_obd *mds, struct lov_desc *desc)
 {
-        struct mds_obd *mds = &obd->u.mds;
         struct obd_run_ctxt saved;
         struct file *f;
         int rc;
 
-        push_ctxt(&saved, &mds->mds_ctxt);
+        push_ctxt(&saved, &mds->mds_ctxt, NULL);
         f = filp_open("LOVDESC", O_RDONLY, 0644);
         if (!f || IS_ERR(f)) {
                 CERROR("Cannot open LOVDESC file\n");
@@ -105,34 +107,33 @@ int mds_get_lovdesc(struct obd_device *obd, struct lov_desc *desc)
         RETURN(0);
 }
 
-int mds_get_lovtgts(struct obd_device *obd, int tgt_count, uuid_t *uuidarray)
+int mds_get_lovtgts(struct mds_obd *mds, int tgt_count,obd_uuid_t *uuidarray)
 {
-        struct mds_obd *mds = &obd->u.mds;
         struct obd_run_ctxt saved;
         struct file *f;
         int rc;
         int rc2;
-        int count;
 
-        push_ctxt(&saved, &mds->mds_ctxt);
+        push_ctxt(&saved, &mds->mds_ctxt, NULL);
         f = filp_open("LOVTGTS", O_RDONLY, 0644);
         if (IS_ERR(f)) {
                 CERROR("Cannot open LOVTGTS file\n");
                 GOTO(out, rc = PTR_ERR(f));
         }
 
-        rc = lustre_fread(f, (char *)uuidarray, tgt_count * sizeof(uuid_t),
+        rc = lustre_fread(f, (char *)uuidarray, tgt_count * sizeof(*uuidarray),
                           &f->f_pos);
         rc2 = filp_close(f, 0);
         if (rc2)
                 CERROR("Error closing LOVTGTS file: rc = %d\n", rc2);
 
-        if (rc != count * sizeof(uuid_t)) {
+        if (rc != tgt_count * sizeof(*uuidarray)) {
                 CERROR("Error reading LOVTGTS file: rc = %d\n", rc);
                 if (rc >= 0)
                         rc = -EIO;
                 GOTO(out, rc);
-        }
+        } else 
+                rc = 0;
         EXIT;
 out:
         pop_ctxt(&saved);
@@ -146,12 +147,29 @@ int mds_iocontrol(long cmd, struct lustre_handle *conn,
         struct obd_device *obd = class_conn2obd(conn);
         struct obd_ioctl_data *data = karg;
         struct lov_desc *desc;
+        obd_uuid_t *uuidarray;
         int count;
         int rc;
 
 
         switch (cmd) {
-        case OBD_IOC_LOV_CONFIG:
+        case OBD_IOC_LOV_SET_CONFIG:
+                desc = (struct lov_desc *)data->ioc_inlbuf1;
+                if (sizeof(*desc) > data->ioc_inllen1) {
+                        CERROR("descriptor size wrong\n");
+                        RETURN(-EINVAL);
+                }
+
+                count = desc->ld_tgt_count;
+                uuidarray = (obd_uuid_t *)data->ioc_inlbuf2;
+                if (sizeof(*uuidarray) * count != data->ioc_inllen2) {
+                        CERROR("UUID array size wrong\n");
+                        RETURN(-EINVAL);
+                }
+                rc = mds_set_lovdesc(obd, desc, uuidarray);
+
+                RETURN(rc);
+        case OBD_IOC_LOV_GET_CONFIG:
                 desc = (struct lov_desc *)data->ioc_inlbuf1;
                 if (sizeof(*desc) > data->ioc_inllen1) {
                         CERROR("descriptor size wrong\n");
@@ -159,11 +177,17 @@ int mds_iocontrol(long cmd, struct lustre_handle *conn,
                 }
 
                 count = desc->ld_tgt_count;
-                if (sizeof(uuid_t) * count != data->ioc_inllen2) {
+                uuidarray = (obd_uuid_t *)data->ioc_inlbuf2;
+                if (sizeof(*uuidarray) * count != data->ioc_inllen2) {
                         CERROR("UUID array size wrong\n");
                         RETURN(-EINVAL);
                 }
-                rc = mds_configure_lov(obd, desc, (uuid_t *)data->ioc_inlbuf2);
+                rc = mds_get_lovdesc(&obd->u.mds, desc);
+                if (desc->ld_tgt_count > count) {
+                        CERROR("UUID array size too small\n");
+                        RETURN(-ENOSPC);
+                }
+                rc = mds_get_lovtgts(&obd->u.mds, desc->ld_tgt_count, uuidarray);
 
                 RETURN(rc);
         default: