Whamcloud - gitweb
LU-10698 obdclass: allow specifying complex jobids
[fs/lustre-release.git] / libcfs / libcfs / linux / linux-curproc.c
index f260225..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, 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>
 
@@ -148,13 +148,18 @@ static int cfs_access_process_vm(struct task_struct *tsk,
        if (down_read_trylock(&mm->mmap_sem) == 0)
                return -EDEADLK;
 
-       /* ignore errors, just check how much was sucessfully transfered */
+       /* ignore errors, just check how much was successfully transferred */
        while (len) {
                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,10 +193,11 @@ 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;
+       bool skip = false;
        ENTRY;
 
        buffer = kmalloc(buf_len, GFP_USER);
@@ -236,13 +242,16 @@ int cfs_get_environ(const char *key, char *value, int *val_len)
                        /* The last entry of this buffer cross the buffer
                         * boundary, reread it in next cycle. */
                        if (unlikely(env_end - env_start == scan_len)) {
-                               /* This entry is too large to fit in buffer */
-                               if (unlikely(scan_len == this_len)) {
-                                       CERROR("Too long env variable.\n");
-                                       GOTO(out, rc = -EINVAL);
-                               }
-                               addr -= scan_len;
+                               /* Just skip the entry larger than page size,
+                                * it can't be jobID env variable. */
+                               if (unlikely(scan_len == this_len))
+                                       skip = true;
+                               else
+                                       addr -= scan_len;
                                break;
+                       } else if (unlikely(skip)) {
+                               skip = false;
+                               goto skip;
                        }
 
                        entry = env_start;
@@ -253,15 +262,20 @@ 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;
                                GOTO(out, rc = 0);
                        }
-
+skip:
                        scan_len -= (env_end - env_start + 1);
                        env_start = env_end + 1;
                }
@@ -279,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);
 
 /*