Whamcloud - gitweb
LU-1329 ptlrpc: resend request on -EINPROGRESS
[fs/lustre-release.git] / lustre / mds / lproc_mds.c
index 343d3fe..bd872fd 100644 (file)
@@ -1,6 +1,4 @@
-/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
- * vim:expandtab:shiftwidth=8:tabstop=8:
- *
+/*
  * GPL HEADER START
  *
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
@@ -28,6 +26,8 @@
 /*
  * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
+ *
+ * Copyright (c) 2012, Whamcloud, Inc.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
@@ -68,26 +68,47 @@ static int lprocfs_mds_wr_evictostnids(struct file *file, const char *buffer,
         return count;
 }
 
+#define BUFLEN (UUID_MAX + 4)
+
 static int lprocfs_mds_wr_evict_client(struct file *file, const char *buffer,
                                        unsigned long count, void *data)
 {
-        struct obd_device *obd = data;
-        struct mds_obd *mds = &obd->u.mds;
-        char tmpbuf[sizeof(struct obd_uuid)];
         struct ptlrpc_request_set *set;
-        int rc;
+        struct obd_device         *obd = data;
+        struct mds_obd            *mds = &obd->u.mds;
+        char                      *kbuf;
+        char                      *tmpbuf;
+        int                        rc;
+
+        OBD_ALLOC(kbuf, BUFLEN);
+        if (kbuf == NULL)
+                return -ENOMEM;
 
-        sscanf(buffer, "%40s", tmpbuf);
+        /*
+         * OBD_ALLOC() will zero kbuf, but we only copy BUFLEN - 1
+         * bytes into kbuf, to ensure that the string is NUL-terminated.
+         * UUID_MAX should include a trailing NUL already.
+         */
+        if (cfs_copy_from_user(kbuf, buffer,
+                               min_t(unsigned long, BUFLEN - 1, count))) {
+                count = -EFAULT;
+                goto out;
+        }
+        tmpbuf = cfs_firststr(kbuf, min_t(unsigned long, BUFLEN - 1, count));
 
-        if (strncmp(tmpbuf, "nid:", 4) != 0)
-                return lprocfs_wr_evict_client(file, buffer, count, data);
+        if (strncmp(tmpbuf, "nid:", 4) != 0) {
+                count = lprocfs_wr_evict_client(file, buffer, count, data);
+                goto out;
+        }
 
         set = ptlrpc_prep_set();
-        if (!set)
-                return -ENOMEM;
+        if (set == NULL) {
+                count = -ENOMEM;
+                goto out;
+        }
 
         if (obd->u.mds.mds_evict_ost_nids) {
-                rc = obd_set_info_async(mds->mds_lov_exp,
+                rc = obd_set_info_async(NULL, mds->mds_lov_exp,
                                         sizeof(KEY_EVICT_BY_NID),
                                         KEY_EVICT_BY_NID, strlen(tmpbuf + 4) + 1,
                                         tmpbuf + 4, set);
@@ -103,7 +124,7 @@ static int lprocfs_mds_wr_evict_client(struct file *file, const char *buffer,
         class_incref(obd, __FUNCTION__, cfs_current());
         LPROCFS_EXIT();
 
-        obd_export_evict_by_nid(obd, tmpbuf+4);
+        obd_export_evict_by_nid(obd, tmpbuf + 4);
 
 
         rc = ptlrpc_set_wait(set);
@@ -115,9 +136,13 @@ static int lprocfs_mds_wr_evict_client(struct file *file, const char *buffer,
         class_decref(obd,  __FUNCTION__, cfs_current());
 
         ptlrpc_set_destroy(set);
+out:
+        OBD_FREE(kbuf, BUFLEN);
         return count;
 }
 
+#undef BUFLEN
+
 static int lprocfs_wr_atime_diff(struct file *file, const char *buffer,
                                  unsigned long count, void *data)
 {