Whamcloud - gitweb
LU-10698 obdclass: allow specifying complex jobids
[fs/lustre-release.git] / libcfs / libcfs / linux / linux-curproc.c
index 3e92367..fee47a2 100644 (file)
  *
  * You should have received a copy of the GNU General Public License
  * version 2 along with this program; If not, see
- * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
- *
- * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
- * CA 95054 USA or visit www.sun.com if you need additional information or
- * have any questions.
+ * http://www.gnu.org/licenses/gpl-2.0.html
  *
  * GPL HEADER END
  */
@@ -27,7 +23,7 @@
  * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
  *
- * Copyright (c) 2012, 2014, Intel Corporation.
+ * Copyright (c) 2012, 2017, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
  */
 
 #include <linux/sched.h>
+#ifdef HAVE_SCHED_HEADERS
+#include <linux/sched/signal.h>
+#include <linux/sched/mm.h>
+#endif
 #include <linux/fs_struct.h>
-
+#include <linux/pagemap.h>
 #include <linux/compat.h>
 #include <linux/thread_info.h>
 
@@ -153,8 +153,13 @@ static int cfs_access_process_vm(struct task_struct *tsk,
                int bytes, rc, offset;
                void *maddr;
 
-               rc = get_user_pages(tsk, mm, addr, 1,
-                                    write, 1, &page, &vma);
+#if defined(HAVE_GET_USER_PAGES_GUP_FLAGS)
+               rc = get_user_pages(addr, 1, write ? FOLL_WRITE : 0, &page, &vma);
+#elif defined(HAVE_GET_USER_PAGES_6ARG)
+               rc = get_user_pages(addr, 1, write, 1, &page, &vma);
+#else
+               rc = get_user_pages(tsk, mm, addr, 1, write, 1, &page, &vma);
+#endif
                if (rc <= 0)
                        break;
 
@@ -173,7 +178,7 @@ static int cfs_access_process_vm(struct task_struct *tsk,
                                            buf, maddr + offset, bytes);
                }
                kunmap(page);
-               page_cache_release(page);
+               put_page(page);
                len -= bytes;
                buf += bytes;
                addr += bytes;
@@ -188,7 +193,7 @@ int cfs_get_environ(const char *key, char *value, int *val_len)
 {
        struct mm_struct *mm;
        char *buffer;
-       int buf_len = PAGE_CACHE_SIZE;
+       int buf_len = PAGE_SIZE;
        int key_len = strlen(key);
        unsigned long addr;
        int rc;
@@ -257,9 +262,14 @@ int cfs_get_environ(const char *key, char *value, int *val_len)
                            !memcmp(entry, key, key_len)) {
                                entry += key_len + 1;
                                entry_len -= key_len + 1;
-                               /* The 'value' buffer passed in is too small.*/
-                               if (entry_len >= *val_len)
+
+                               /* The 'value' buffer passed in is too small.
+                                * Copy what fits, but return -EOVERFLOW. */
+                               if (entry_len >= *val_len) {
+                                       memcpy(value, entry, *val_len);
+                                       value[*val_len - 1] = 0;
                                        GOTO(out, rc = -EOVERFLOW);
+                               }
 
                                memcpy(value, entry, entry_len);
                                *val_len = entry_len;
@@ -283,7 +293,6 @@ EXPORT_SYMBOL(cfs_cap_raise);
 EXPORT_SYMBOL(cfs_cap_lower);
 EXPORT_SYMBOL(cfs_cap_raised);
 EXPORT_SYMBOL(cfs_curproc_cap_pack);
-EXPORT_SYMBOL(cfs_curproc_cap_unpack);
 EXPORT_SYMBOL(cfs_capable);
 
 /*