File nscd-senfile.patch of Package glibc.18276

2018-05-16  Adhemerval Zanella  <adhemerval.zanella@linaro.org>

	[BZ #23178]
	* nscd/nscd-client.h (sendfileall): Remove prototype.
	* nscd/connections.c [HAVE_SENDFILE] (sendfileall): Remove function.
	(handle_request): Use writeall instead of sendfileall.
	* nscd/aicache.c (addhstaiX): Likewise.
	* nscd/grpcache.c (cache_addgr): Likewise.
	* nscd/hstcache.c (cache_addhst): Likewise.
	* nscd/initgrcache.c (addinitgroupsX): Likewise.
	* nscd/netgroupcache.c (addgetnetgrentX, addinnetgrX): Likewise.
	* nscd/pwdcache.c (cache_addpw): Likewise.
	* nscd/servicescache.c (cache_addserv): Likewise.
	* sysdeps/unix/sysv/linux/Makefile [$(subdir) == nscd]
	(sysdep-CFLAGS): Remove -DHAVE_SENDFILE.
	* sysdeps/unix/sysv/linux/kernel-features.h (__ASSUME_SENDFILE):
	Remove define.

Index: glibc-2.26/nscd/aicache.c
===================================================================
--- glibc-2.26.orig/nscd/aicache.c
+++ glibc-2.26/nscd/aicache.c
@@ -31,9 +31,6 @@
 
 #include "dbg_log.h"
 #include "nscd.h"
-#ifdef HAVE_SENDFILE
-# include <kernel-features.h>
-#endif
 
 
 typedef enum nss_status (*nss_gethostbyname4_r)
@@ -447,32 +444,7 @@ addhstaiX (struct database_dyn *db, int
 	     would unnecessarily let the receiver wait.  */
 	  assert (fd != -1);
 
-#ifdef HAVE_SENDFILE
-	  if (__builtin_expect (db->mmap_used, 1) && !alloca_used)
-	    {
-	      assert (db->wr_fd != -1);
-	      assert ((char *) &dataset->resp > (char *) db->data);
-	      assert ((char *) dataset - (char *) db->head + total
-		      <= (sizeof (struct database_pers_head)
-			  + db->head->module * sizeof (ref_t)
-			  + db->head->data_size));
-# ifndef __ASSUME_SENDFILE
-	      ssize_t written;
-	      written =
-# endif
-		sendfileall (fd, db->wr_fd, (char *) &dataset->resp
-			     - (char *) db->head, dataset->head.recsize);
-# ifndef __ASSUME_SENDFILE
-	      if (written == -1 && errno == ENOSYS)
-		goto use_write;
-# endif
-	    }
-	  else
-# ifndef __ASSUME_SENDFILE
-	  use_write:
-# endif
-#endif
-	    writeall (fd, &dataset->resp, dataset->head.recsize);
+	  writeall (fd, &dataset->resp, dataset->head.recsize);
 	}
 
       goto out;
Index: glibc-2.26/nscd/connections.c
===================================================================
--- glibc-2.26.orig/nscd/connections.c
+++ glibc-2.26/nscd/connections.c
@@ -46,9 +46,6 @@
 #include <sys/mman.h>
 #include <sys/param.h>
 #include <sys/poll.h>
-#ifdef HAVE_SENDFILE
-# include <sys/sendfile.h>
-#endif
 #include <sys/socket.h>
 #include <sys/stat.h>
 #include <sys/un.h>
@@ -279,26 +276,6 @@ writeall (int fd, const void *buf, size_
 }
 
 
-#ifdef HAVE_SENDFILE
-ssize_t
-sendfileall (int tofd, int fromfd, off_t off, size_t len)
-{
-  ssize_t n = len;
-  ssize_t ret;
-
-  do
-    {
-      ret = TEMP_FAILURE_RETRY (sendfile (tofd, fromfd, &off, n));
-      if (ret <= 0)
-	break;
-      n -= ret;
-    }
-  while (n > 0);
-  return ret < 0 ? ret : len - n;
-}
-#endif
-
-
 enum usekey
   {
     use_not = 0,
@@ -1156,35 +1133,8 @@ request from '%s' [%ld] not handled due
       if (cached != NULL)
 	{
 	  /* Hurray it's in the cache.  */
-	  ssize_t nwritten;
-
-#ifdef HAVE_SENDFILE
-	  if (__glibc_likely (db->mmap_used))
-	    {
-	      assert (db->wr_fd != -1);
-	      assert ((char *) cached->data > (char *) db->data);
-	      assert ((char *) cached->data - (char *) db->head
-		      + cached->recsize
-		      <= (sizeof (struct database_pers_head)
-			  + db->head->module * sizeof (ref_t)
-			  + db->head->data_size));
-	      nwritten = sendfileall (fd, db->wr_fd,
-				      (char *) cached->data
-				      - (char *) db->head, cached->recsize);
-# ifndef __ASSUME_SENDFILE
-	      if (nwritten == -1 && errno == ENOSYS)
-		goto use_write;
-# endif
-	    }
-	  else
-# ifndef __ASSUME_SENDFILE
-	  use_write:
-# endif
-#endif
-	    nwritten = writeall (fd, cached->data, cached->recsize);
-
-	  if (nwritten != cached->recsize
-	      && __builtin_expect (debug_level, 0) > 0)
+	  if (writeall (fd, cached->data, cached->recsize) != cached->recsize
+	      && __glibc_unlikely (debug_level > 0))
 	    {
 	      /* We have problems sending the result.  */
 	      char buf[256];
Index: glibc-2.26/nscd/grpcache.c
===================================================================
--- glibc-2.26.orig/nscd/grpcache.c
+++ glibc-2.26/nscd/grpcache.c
@@ -35,9 +35,6 @@
 
 #include "nscd.h"
 #include "dbg_log.h"
-#ifdef HAVE_SENDFILE
-# include <kernel-features.h>
-#endif
 
 /* This is the standard reply in case the service is disabled.  */
 static const gr_response_header disabled =
@@ -318,37 +315,9 @@ cache_addgr (struct database_dyn *db, in
 	     unnecessarily let the receiver wait.  */
 	  assert (fd != -1);
 
-#ifdef HAVE_SENDFILE
-	  if (__builtin_expect (db->mmap_used, 1) && ! dataset_temporary)
-	    {
-	      assert (db->wr_fd != -1);
-	      assert ((char *) &dataset->resp > (char *) db->data);
-	      assert ((char *) dataset - (char *) db->head
-		      + total
-		      <= (sizeof (struct database_pers_head)
-			  + db->head->module * sizeof (ref_t)
-			  + db->head->data_size));
-	      ssize_t written = sendfileall (fd, db->wr_fd,
-					     (char *) &dataset->resp
-					     - (char *) db->head,
-					     dataset->head.recsize);
-	      if (written != dataset->head.recsize)
-		{
-# ifndef __ASSUME_SENDFILE
-		  if (written == -1 && errno == ENOSYS)
-		    goto use_write;
-# endif
-		  all_written = false;
-		}
-	    }
-	  else
-# ifndef __ASSUME_SENDFILE
-	  use_write:
-# endif
-#endif
-	    if (writeall (fd, &dataset->resp, dataset->head.recsize)
-		!= dataset->head.recsize)
-	      all_written = false;
+	  if (writeall (fd, &dataset->resp, dataset->head.recsize)
+	      != dataset->head.recsize)
+	    all_written = false;
 	}
 
       /* Add the record to the database.  But only if it has not been
Index: glibc-2.26/nscd/hstcache.c
===================================================================
--- glibc-2.26.orig/nscd/hstcache.c
+++ glibc-2.26/nscd/hstcache.c
@@ -37,9 +37,6 @@
 
 #include "nscd.h"
 #include "dbg_log.h"
-#ifdef HAVE_SENDFILE
-# include <kernel-features.h>
-#endif
 
 
 /* This is the standard reply in case the service is disabled.  */
@@ -352,37 +349,9 @@ cache_addhst (struct database_dyn *db, i
 	     unnecessarily keep the receiver waiting.  */
 	  assert (fd != -1);
 
-#ifdef HAVE_SENDFILE
-	  if (__builtin_expect (db->mmap_used, 1) && !alloca_used)
-	    {
-	      assert (db->wr_fd != -1);
-	      assert ((char *) &dataset->resp > (char *) db->data);
-	      assert ((char *) dataset - (char *) db->head
-		      + total
-		      <= (sizeof (struct database_pers_head)
-			  + db->head->module * sizeof (ref_t)
-			  + db->head->data_size));
-	      ssize_t written = sendfileall (fd, db->wr_fd,
-					     (char *) &dataset->resp
-					     - (char *) db->head,
-					     dataset->head.recsize);
-	      if (written != dataset->head.recsize)
-		{
-# ifndef __ASSUME_SENDFILE
-		  if (written == -1 && errno == ENOSYS)
-		    goto use_write;
-# endif
-		  all_written = false;
-		}
-	    }
-	  else
-# ifndef __ASSUME_SENDFILE
-	  use_write:
-# endif
-#endif
-	    if (writeall (fd, &dataset->resp, dataset->head.recsize)
-		!= dataset->head.recsize)
-	      all_written = false;
+	  if (writeall (fd, &dataset->resp, dataset->head.recsize)
+	      != dataset->head.recsize)
+	    all_written = false;
 	}
 
       /* Add the record to the database.  But only if it has not been
Index: glibc-2.26/nscd/initgrcache.c
===================================================================
--- glibc-2.26.orig/nscd/initgrcache.c
+++ glibc-2.26/nscd/initgrcache.c
@@ -29,9 +29,6 @@
 
 #include "dbg_log.h"
 #include "nscd.h"
-#ifdef HAVE_SENDFILE
-# include <kernel-features.h>
-#endif
 
 #include "../nss/nsswitch.h"
 
@@ -353,37 +350,9 @@ addinitgroupsX (struct database_dyn *db,
 	     unnecessarily let the receiver wait.  */
 	  assert (fd != -1);
 
-#ifdef HAVE_SENDFILE
-	  if (__builtin_expect (db->mmap_used, 1) && !alloca_used)
-	    {
-	      assert (db->wr_fd != -1);
-	      assert ((char *) &dataset->resp > (char *) db->data);
-	      assert ((char *) dataset - (char *) db->head
-		      + total
-		      <= (sizeof (struct database_pers_head)
-			  + db->head->module * sizeof (ref_t)
-			  + db->head->data_size));
-	      ssize_t written = sendfileall (fd, db->wr_fd,
-					     (char *) &dataset->resp
-					     - (char *) db->head,
-					     dataset->head.recsize);
-	      if (written != dataset->head.recsize)
-		{
-# ifndef __ASSUME_SENDFILE
-		  if (written == -1 && errno == ENOSYS)
-		    goto use_write;
-# endif
-		  all_written = false;
-		}
-	    }
-	  else
-# ifndef __ASSUME_SENDFILE
-	  use_write:
-# endif
-#endif
-	    if (writeall (fd, &dataset->resp, dataset->head.recsize)
-		!= dataset->head.recsize)
-	      all_written = false;
+	  if (writeall (fd, &dataset->resp, dataset->head.recsize)
+	      != dataset->head.recsize)
+	    all_written = false;
 	}
 
 
Index: glibc-2.26/nscd/netgroupcache.c
===================================================================
--- glibc-2.26.orig/nscd/netgroupcache.c
+++ glibc-2.26/nscd/netgroupcache.c
@@ -413,33 +413,7 @@ addgetnetgrentX (struct database_dyn *db
 	 since while inserting this thread might block and so would
 	 unnecessarily let the receiver wait.  */
     writeout:
-#ifdef HAVE_SENDFILE
-      if (__builtin_expect (db->mmap_used, 1) && cacheable)
-	{
-	  assert (db->wr_fd != -1);
-	  assert ((char *) &dataset->resp > (char *) db->data);
-	  assert ((char *) dataset - (char *) db->head + total
-		  <= (sizeof (struct database_pers_head)
-		      + db->head->module * sizeof (ref_t)
-		      + db->head->data_size));
-# ifndef __ASSUME_SENDFILE
-	  ssize_t written =
-# endif
-	    sendfileall (fd, db->wr_fd, (char *) &dataset->resp
-			 - (char *) db->head, dataset->head.recsize);
-# ifndef __ASSUME_SENDFILE
-	  if (written == -1 && errno == ENOSYS)
-	    goto use_write;
-# endif
-	}
-      else
-#endif
-	{
-#if defined HAVE_SENDFILE && !defined __ASSUME_SENDFILE
-	use_write:
-#endif
-	  writeall (fd, &dataset->resp, dataset->head.recsize);
-	}
+      writeall (fd, &dataset->resp, dataset->head.recsize);
     }
 
   if (cacheable)
@@ -592,36 +566,9 @@ addinnetgrX (struct database_dyn *db, in
       /* We write the dataset before inserting it to the database
 	 since while inserting this thread might block and so would
 	 unnecessarily let the receiver wait.  */
-       assert (fd != -1);
+      assert (fd != -1);
 
-#ifdef HAVE_SENDFILE
-      if (__builtin_expect (db->mmap_used, 1) && cacheable)
-	{
-	  assert (db->wr_fd != -1);
-	  assert ((char *) &dataset->resp > (char *) db->data);
-	  assert ((char *) dataset - (char *) db->head + sizeof (*dataset)
-		  <= (sizeof (struct database_pers_head)
-		      + db->head->module * sizeof (ref_t)
-		      + db->head->data_size));
-# ifndef __ASSUME_SENDFILE
-	  ssize_t written =
-# endif
-	    sendfileall (fd, db->wr_fd,
-			 (char *) &dataset->resp - (char *) db->head,
-			 sizeof (innetgroup_response_header));
-# ifndef __ASSUME_SENDFILE
-	  if (written == -1 && errno == ENOSYS)
-	    goto use_write;
-# endif
-	}
-      else
-#endif
-	{
-#if defined HAVE_SENDFILE && !defined __ASSUME_SENDFILE
-	use_write:
-#endif
-	  writeall (fd, &dataset->resp, sizeof (innetgroup_response_header));
-	}
+      writeall (fd, &dataset->resp, sizeof (innetgroup_response_header));
     }
 
   if (cacheable)
Index: glibc-2.26/nscd/nscd-client.h
===================================================================
--- glibc-2.26.orig/nscd/nscd-client.h
+++ glibc-2.26/nscd/nscd-client.h
@@ -443,8 +443,6 @@ extern ssize_t __readvall (int fd, const
   attribute_hidden;
 extern ssize_t writeall (int fd, const void *buf, size_t len)
   attribute_hidden;
-extern ssize_t sendfileall (int tofd, int fromfd, off_t off, size_t len)
-  attribute_hidden;
 
 /* Get netlink timestamp counter from mapped area or zero.  */
 extern uint32_t __nscd_get_nl_timestamp (void);
Index: glibc-2.26/nscd/pwdcache.c
===================================================================
--- glibc-2.26.orig/nscd/pwdcache.c
+++ glibc-2.26/nscd/pwdcache.c
@@ -35,9 +35,6 @@
 
 #include "nscd.h"
 #include "dbg_log.h"
-#ifdef HAVE_SENDFILE
-# include <kernel-features.h>
-#endif
 
 /* This is the standard reply in case the service is disabled.  */
 static const pw_response_header disabled =
@@ -296,37 +293,9 @@ cache_addpw (struct database_dyn *db, in
 	     unnecessarily let the receiver wait.  */
 	  assert (fd != -1);
 
-#ifdef HAVE_SENDFILE
-	  if (__builtin_expect (db->mmap_used, 1) && !alloca_used)
-	    {
-	      assert (db->wr_fd != -1);
-	      assert ((char *) &dataset->resp > (char *) db->data);
-	      assert ((char *) dataset - (char *) db->head
-		      + total
-		      <= (sizeof (struct database_pers_head)
-			  + db->head->module * sizeof (ref_t)
-			  + db->head->data_size));
-	      ssize_t written = sendfileall (fd, db->wr_fd,
-					     (char *) &dataset->resp
-					     - (char *) db->head,
-					     dataset->head.recsize);
-	      if (written != dataset->head.recsize)
-		{
-# ifndef __ASSUME_SENDFILE
-		  if (written == -1 && errno == ENOSYS)
-		    goto use_write;
-# endif
-		  all_written = false;
-		}
-	    }
-	  else
-# ifndef __ASSUME_SENDFILE
-	  use_write:
-# endif
-#endif
-	    if (writeall (fd, &dataset->resp, dataset->head.recsize)
-		!= dataset->head.recsize)
-	      all_written = false;
+	  if (writeall (fd, &dataset->resp, dataset->head.recsize)
+	      != dataset->head.recsize)
+	    all_written = false;
 	}
 
 
Index: glibc-2.26/nscd/servicescache.c
===================================================================
--- glibc-2.26.orig/nscd/servicescache.c
+++ glibc-2.26/nscd/servicescache.c
@@ -278,37 +278,9 @@ cache_addserv (struct database_dyn *db,
 	     unnecessarily keep the receiver waiting.  */
 	  assert (fd != -1);
 
-#ifdef HAVE_SENDFILE
-	  if (__builtin_expect (db->mmap_used, 1) && !alloca_used)
-	    {
-	      assert (db->wr_fd != -1);
-	      assert ((char *) &dataset->resp > (char *) db->data);
-	      assert ((char *) dataset - (char *) db->head
-		      + total
-		      <= (sizeof (struct database_pers_head)
-			  + db->head->module * sizeof (ref_t)
-			  + db->head->data_size));
-	      ssize_t written = sendfileall (fd, db->wr_fd,
-					     (char *) &dataset->resp
-					     - (char *) db->head,
-					     dataset->head.recsize);
-	      if (written != dataset->head.recsize)
-		{
-# ifndef __ASSUME_SENDFILE
-		  if (written == -1 && errno == ENOSYS)
-		    goto use_write;
-# endif
-		  all_written = false;
-		}
-	    }
-	  else
-# ifndef __ASSUME_SENDFILE
-	  use_write:
-# endif
-#endif
-	    if (writeall (fd, &dataset->resp, dataset->head.recsize)
-		!= dataset->head.recsize)
-	      all_written = false;
+	  if (writeall (fd, &dataset->resp, dataset->head.recsize)
+	      != dataset->head.recsize)
+	    all_written = false;
 	}
 
       /* Add the record to the database.  But only if it has not been
Index: glibc-2.26/sysdeps/unix/sysv/linux/Makefile
===================================================================
--- glibc-2.26.orig/sysdeps/unix/sysv/linux/Makefile
+++ glibc-2.26/sysdeps/unix/sysv/linux/Makefile
@@ -219,7 +219,7 @@ CFLAGS-mq_receive.c += -fexceptions
 endif
 
 ifeq ($(subdir),nscd)
-sysdep-CFLAGS += -DHAVE_EPOLL -DHAVE_SENDFILE -DHAVE_INOTIFY -DHAVE_NETLINK
+sysdep-CFLAGS += -DHAVE_EPOLL -DHAVE_INOTIFY -DHAVE_NETLINK
 CFLAGS-gai.c += -DNEED_NETLINK
 endif
 
Index: glibc-2.26/sysdeps/unix/sysv/linux/kernel-features.h
===================================================================
--- glibc-2.26.orig/sysdeps/unix/sysv/linux/kernel-features.h
+++ glibc-2.26/sysdeps/unix/sysv/linux/kernel-features.h
@@ -37,9 +37,6 @@
    introduced.  If somebody cares these values can afterwards be
    corrected.  */
 
-/* The sendfile syscall was introduced in 2.2.0.  */
-#define __ASSUME_SENDFILE		1
-
 /* Some architectures use the socketcall multiplexer for some or all
    socket-related operations instead of separate syscalls.
    __ASSUME_SOCKETCALL is defined for such architectures.  */
openSUSE Build Service is sponsored by