fix rtt

fix rtt

--- src/tcpcopy/tc_session.c
+++ src/tcpcopy/tc_session.c
@@ -844,7 +844,7 @@
     }

     if (s->sm.rtt_cal == RTT_CAL) {
-        if (s->first_resp_unack_time) {
+        if (s->first_resp_unack_time || s->sm.status == SYN_CONFIRM) {
             if ((tc_milliscond_time() - s->first_resp_unack_time) < s->rtt) {
                 tc_log_info(LOG_NOTICE, 0,
                         "rtt:%ld,cur:%ld,resp:%ld,p:%u",
@@ -1987,6 +1987,10 @@
     s->vir_ack_seq = htonl(ntohl(tcp_header->seq) + 1);
     s->sm.dst_closed  = 0;
     s->sm.reset_sent  = 0;
+
+    if (s->first_resp_unack_time == 0) {
+        s->first_resp_unack_time = tc_milliscond_time();
+    }

     if (s->sm.req_halfway_intercepted) {
         send_faked_third_handshake(s, ip_header, tcp_header);


Changes for RTC peripheral status

Changes for RTC peripheral status

--- targets/TARGET_TOSHIBA/TARGET_TMPM3H6/rtc_api.c
+++ targets/TARGET_TOSHIBA/TARGET_TMPM3H6/rtc_api.c
@@ -34,16 +34,16 @@
 #define HEX2DEC(val)                    ((val >> 4U) * 10U + val % 16U)  // Hex to Dec conversion macro
 #define DEC2HEX(val)                    ((val / 10U) * 16U + val % 10U)  // Dec to Hex conversion macro

-static int flag = 0;
+static int rtc_inited = 0;
 static int diff_year = 100;         //our RTC register only support 2000~2099
 static void external_losc_enable(void);

 void rtc_init(void)
 {
-    if (!flag) {
+    if (!rtc_inited) {
         TSB_CG_FSYSENB_IPENB03 = 1;  // Enable Sys Clock for RTC
         external_losc_enable();      // Enable low-speed oscillator
-        TSB_RTC->PAGER = 0x00;       //disable clock and alarm
+        TSB_RTC->PAGER = 0x00;       // Disable clock and alarm

         while ((TSB_RTC->RESTR & RTCRESTR_RSTTMR_MASK) == RTCRESTR_RSTTMR_R_RUN) {
             // Reset RTC sec counter
@@ -66,24 +66,27 @@
         TSB_RTC->MINR    = (uint8_t)0x02;     // Set minute value
         TSB_RTC->SECR    = (uint8_t)0x22;     // Set second value
         TSB_RTC->PAGER  |= RTC_CLK_ENABLE;    // Enable Clock
-        flag             = 1;                 // Enable internal flag
+        rtc_inited       = 1;                 // Enable RTC initialzed status
     }
 }

 void rtc_free(void)
 {
-    if (flag) {  // Check status of RTC peripheral driver is ENABLE or DISABLE
-        flag = 0;  // Set status of RTC peripheral driver is DISABLE
-    }
+    rtc_inited = 0;  // Set status of RTC peripheral driver as DISABLE
 }

 int rtc_isenabled(void)
 {
-    return flag;  // Return a flag that represents status of RTC peripheral driver
+    return rtc_inited;  // Return status of RTC peripheral driver
 }

 time_t rtc_read(void)
 {
+    if (!rtc_inited) {
+        // Return invalid time for now!
+        return 0;
+    }
+
     struct tm timeinfo;
     uint8_t read_1 = 0U;
     uint8_t read_2 = 0U;
@@ -141,6 +144,11 @@

 void rtc_write(time_t t)
 {
+    if (!rtc_inited) {
+        // Initialize the RTC as not yet initialized
+        rtc_init();
+    }
+
     struct tm timeinfo;
     if (_rtc_localtime(t, &timeinfo, RTC_4_YEAR_LEAP_YEAR_SUPPORT) == false) {
         return;


Manually output simple numbers

Manually output simple numbers

--- NULLC/Output.h
+++ NULLC/Output.h
@@ -118,15 +118,62 @@

 				Print(str, length);
 			}
+			else if(pos[0] == '%' && pos[1] == '%')
+			{
+				pos += 2;
+
+				Print('%');
+			}
+			else if(pos[0] == '%' && pos[1] == 'd')
+			{
+				pos += 2;
+
+				int value = va_arg(args, int);
+
+				if(value < 0)
+					Print('-');
+
+				unsigned uvalue;
+
+				if(value < 0)
+					uvalue = -value;
+				else
+					uvalue = value;
+
+				char reverse[16];
+
+				char *curr = reverse;
+
+				*curr++ = (char)((uvalue % 10) + '0');
+
+				while(uvalue /= 10)
+					*curr++ = (char)((uvalue % 10) + '0');
+
+				char forward[16];
+
+				char *result = forward;
+
+				do
+				{
+					--curr;
+					*result++ = *curr;
+				}
+				while(curr != reverse);
+
+				*result = 0;
+
+				Print(forward);
+			}
+			else if(pos[0] == 0)
+			{
+				return;
+			}
 			else
 			{
 				break;
 			}

 		}
-
-		if(!*pos)
-			return;

 		int length = vsnprintf(tempBuf, tempBufSize - 1, pos, args);


[cc2-qbe] Add OPTR operation

[cc2-qbe] Add OPTR operation

In this case we only have to load twice the child
of the node.

--- cc2/arch/qbe/cgen.c
+++ cc2/arch/qbe/cgen.c
@@ -290,7 +290,10 @@
 	case OPAR:
 	case ONEG:
 	case OADDR:
+		abort();
 	case OPTR:
+		np->left = load(load(l));
+		return tmpnode(np);
 	case OINC:
 	case ODEC:
 		abort();


Bug 455829: read from /dev/urandom instead of /dev/random because /dev/random may block for a long time.  The patch is contributed by Mike Hommey <mh+mozilla@glandium.org>.  r=wtc.

--- pr/src/md/unix/uxrng.c
+++ pr/src/md/unix/uxrng.c
@@ -151,39 +151,39 @@
 #include <sys/stat.h>
 #include <fcntl.h>

-static int      fdDevRandom;
-static PRCallOnceType coOpenDevRandom;
-
-static PRStatus OpenDevRandom( void )
-{
-    fdDevRandom = open( "/dev/random", O_RDONLY );
-    return((-1 == fdDevRandom)? PR_FAILURE : PR_SUCCESS );
-} /* end OpenDevRandom() */
-
-static size_t GetDevRandom( void *buf, size_t size )
+static int      fdDevURandom;
+static PRCallOnceType coOpenDevURandom;
+
+static PRStatus OpenDevURandom( void )
+{
+    fdDevURandom = open( "/dev/urandom", O_RDONLY );
+    return((-1 == fdDevURandom)? PR_FAILURE : PR_SUCCESS );
+} /* end OpenDevURandom() */
+
+static size_t GetDevURandom( void *buf, size_t size )
 {
     int bytesIn;
     int rc;

-    rc = PR_CallOnce( &coOpenDevRandom, OpenDevRandom );
+    rc = PR_CallOnce( &coOpenDevURandom, OpenDevURandom );
     if ( PR_FAILURE == rc ) {
         _PR_MD_MAP_OPEN_ERROR( errno );
         return(0);
     }

-    bytesIn = read( fdDevRandom, buf, size );
+    bytesIn = read( fdDevURandom, buf, size );
     if ( -1 == bytesIn ) {
         _PR_MD_MAP_READ_ERROR( errno );
         return(0);
     }

     return( bytesIn );
-} /* end GetDevRandom() */
+} /* end GetDevURandom() */

 static size_t
 GetHighResClock(void *buf, size_t maxbytes)
 {
-    return(GetDevRandom( buf, maxbytes ));
+    return(GetDevURandom( buf, maxbytes ));
 }


fs/eventpoll.c: fix spelling

fs/eventpoll.c: fix spelling

eventpoll.c has wonderful comments but some annoying typos
sneaked in:
	* toepoll_ctl -> to epoll_ctl
	* rapresent -> represents
	* sructure -> structure
	* machanism -> mechanism
	* trasfering -> transferring

Signed-off-by: Daniel Baluta <f45a6396254d0683f1df8e14b691f61d753fe117@gmail.com>
Signed-off-by: Jiri Kosina <ed58f755cc8caaf10c3e8c731a8b86fb8f13d6cb@suse.cz>

--- fs/eventpoll.c
+++ fs/eventpoll.c
@@ -62,7 +62,7 @@
  * This mutex is acquired by ep_free() during the epoll file
  * cleanup path and it is also acquired by eventpoll_release_file()
  * if a file has been pushed inside an epoll set and it is then
- * close()d without a previous call toepoll_ctl(EPOLL_CTL_DEL).
+ * close()d without a previous call to epoll_ctl(EPOLL_CTL_DEL).
  * It is possible to drop the "ep->mtx" and to use the global
  * mutex "epmutex" (together with "ep->lock") to have it working,
  * but having "ep->mtx" will make the interface more scalable.
@@ -145,11 +145,11 @@

 /*
  * This structure is stored inside the "private_data" member of the file
- * structure and rapresent the main data sructure for the eventpoll
+ * structure and represents the main data structure for the eventpoll
  * interface.
  */
 struct eventpoll {
-	/* Protect the this structure access */
+	/* Protect the access to this structure */
 	spinlock_t lock;

 	/*
@@ -783,7 +783,7 @@

 /*
  * This is the callback that is passed to the wait queue wakeup
- * machanism. It is called by the stored file descriptors when they
+ * mechanism. It is called by the stored file descriptors when they
  * have events to report.
  */
 static int ep_poll_callback(wait_queue_t *wait, unsigned mode, int sync, void *key)
@@ -814,9 +814,9 @@
 		goto out_unlock;

 	/*
-	 * If we are trasfering events to userspace, we can hold no locks
+	 * If we are transferring events to userspace, we can hold no locks
 	 * (because we're accessing user memory, and because of linux f_op->poll()
-	 * semantics). All the events that happens during that period of time are
+	 * semantics). All the events that happen during that period of time are
 	 * chained in ep->ovflist and requeued later on.
 	 */
 	if (unlikely(ep->ovflist != EP_UNACTIVE_PTR)) {


[Modify] docs

[Modify] docs

--- LYCategory/Classes/_UIKit/UIViewController+Operator.h
+++ LYCategory/Classes/_UIKit/UIViewController+Operator.h
@@ -49,6 +49,11 @@
  */
 - (void)observeNotifName:(NSString *)notifName selector:(SEL)selector;

+/**
+ Removes matching entries from the notification center's dispatch table.
+
+ @param notifName Name of the notification to remove from dispatch table. Specify a notification name to remove only entries that specify this notification name. When nil, the receiver does not use notification names as criteria for removal.
+ */
 - (void)removeObservingNotifName:(NSString *)notifName;

 @end


make internal test functions static

make internal test functions static

--- tests/test-conveniences.c
+++ tests/test-conveniences.c
@@ -112,21 +112,22 @@
 }

-bool
+static bool
 get_exists_operator (const bson_value_t *value,
                      bool               *exists);

-bool find (bson_value_t *value,
-           const bson_iter_t *iter,
-           const char *key,
-           bool is_command,
-           bool is_first);
-
-bool
+static bool
+find (bson_value_t *value,
+      const bson_iter_t *iter,
+      const char *key,
+      bool is_command,
+      bool is_first);
+
+static bool
 bson_value_equal (const bson_value_t *a,
                   const bson_value_t *b);

-bool
+static bool
 match_bson (const bson_t *doc,
             const bson_t *pattern,
             bool          is_command);
@@ -258,7 +259,7 @@
  *--------------------------------------------------------------------------
  */

-bool
+static bool
 match_bson (const bson_t *doc,
             const bson_t *pattern,
             bool          is_command)
@@ -335,7 +336,7 @@
  *--------------------------------------------------------------------------
  */

-bool
+static bool
 find (bson_value_t *value,
       const bson_iter_t *iter,
       const char *key,
@@ -368,7 +369,7 @@
 }

-bool
+static bool
 bson_init_from_value (bson_t             *b,
                       const bson_value_t *v)
 {
@@ -395,7 +396,7 @@
  *--------------------------------------------------------------------------
  */

-bool
+static bool
 get_exists_operator (const bson_value_t *value,
                      bool               *exists)
 {
@@ -413,7 +414,7 @@
 }

-bool
+static bool
 match_bson_arrays (const bson_t *a,
                    const bson_t *b)
 {
@@ -427,7 +428,7 @@
 }

-bool
+static bool
 bson_value_equal (const bson_value_t *a,
                   const bson_value_t *b)
 {


staging: lustre: ldlm: Do not export static function

Remove the export symbol for static function.

The semantic patch used to find this is:

// <smpl>
@r@
type T;
identifier f;
@@

static T f (...) { ... }

@@
identifier r.f;
declarer name EXPORT_SYMBOL;
@@

-EXPORT_SYMBOL(f);
// </smpl>

Signed-off-by: Amitoj Kaur Chawla <4515e699e2ac78ad2253451343b05f644c855b8c@gmail.com>
Signed-off-by: Greg Kroah-Hartman <4645f7897fd33786a2ee1264d590b3c400559d85@linuxfoundation.org>

--- drivers/staging/lustre/lustre/ldlm/ldlm_pool.c
+++ drivers/staging/lustre/lustre/ldlm/ldlm_pool.c
@@ -1005,7 +1005,6 @@
 	}
 	return time;
 }
-EXPORT_SYMBOL(ldlm_pools_recalc);

 static int ldlm_pools_thread_main(void *arg)
 {


link-parser: Disallow unknown arguments

link-parser: Disallow unknown arguments

--- link-parser/link-parser.c
+++ link-parser/link-parser.c
@@ -634,6 +634,11 @@
 			if ((var[0] != '!') && issue_special_command(var, copts, NULL))
 				print_usage(argv[0]);
 		}
+		else if (i != 1)
+		{
+			prt_error("Fatal error: Unknown argument '%s'.\n", argv[i]);
+			print_usage(argv[0]);
+		}
 	}

 #ifdef _WIN32


Fixed a warning.

Fixed a warning.

--- test/ut_vec.c
+++ test/ut_vec.c
@@ -162,7 +162,7 @@

     pq = vecget(point_t,v,3);
     if (!logcheck(pq && pq->x == q.x && pq->y == q.y)) {
-      if (pq) logprintf("pq: %p pq->x:%f pq->y:%f",pq, pq->x, pq->y);
+      if (pq) logprintf("pq: %p pq->x:%f pq->y:%f",(void *)pq, pq->x, pq->y);
       else logprintf("pq is NULL");
     }
   }


Fix breakage when re-tagging notes with tags as substrings.

--- src/ntx.c
+++ src/ntx.c
@@ -33,8 +33,8 @@
 /* Default (_one character_) separators.            *
  * \n the a hard-coded record separator, due to the *
  * fgets style of line handling.                    */
-const char ID_SEP    = '\t';
-const char FIELD_SEP = ';';
+const char  ID_SEP    = '\t';
+const char *FIELD_SEP = ";";

 /* Builtin Subdirectories. */
@@ -68,6 +68,38 @@
   fputs("\n", stderr);

   exit(EXIT_FAILURE);
+}
+
+char **strtokens(char *str, const char *delim)
+{
+  unsigned int curtoken = 0, maxtokens = 8;
+  char **tokens = alloc(maxtokens * sizeof(char *));
+  char *token;
+
+  if(strlen(delim) == 0) {
+    if(tokens) release(tokens);
+    return NULL;
+  }
+
+  /* Collect tokens from strtok. */
+  for(token = strtok(str, delim); token; token = strtok(NULL, delim)) {
+    if(curtoken == maxtokens)
+      tokens = ralloc(tokens, (maxtokens *= 2));
+    tokens[curtoken++] = token;
+  }
+
+  /* Terminate with a NULL token. */
+  if(curtoken+1 == maxtokens)
+    tokens = ralloc(tokens, maxtokens+1);
+  tokens[curtoken] = NULL;
+
+  return tokens;
+}
+
+char **strrtokens(const char *str, char **buffer, const char *delim)
+{
+  *buffer = strdupe((char*)str);
+  return strtokens(*buffer, delim);
 }

 /* 'buf' should be SUMMARY_LENGTH + PADDING_LENGTH bytes long. */
@@ -127,7 +159,7 @@
   for(cur = tags; *cur; cur++) {
     strcpy(pos, *cur);
     len = strlen(*cur);
-    pos[len] = FIELD_SEP;
+    pos[len] = *FIELD_SEP;
     pos += len + 1;
   }

@@ -263,7 +295,7 @@
   /* XXX: If we can't reread the file, do we need to take action? */
   ntx_summary(file, note + SUMMARY_OFFSET);
   if(strcmp(head, note + SUMMARY_OFFSET)) {
-    char *tags, *cur, *ptr;
+    char *tags, *cur;

     /* Fill in the identification information. */
     strncpy(note, id, ID_LENGTH);
@@ -273,10 +305,9 @@
     if(!(tags = ntx_find(file, id)))
       die("Unable to locate note %s in %s.", id, file);

-    for(cur = tags + SUMMARY_OFFSET; (ptr = strchr(cur, FIELD_SEP));
-        cur = ptr + 1) {
-      *ptr = '\0';
-
+    for(cur = strtok(tags + SUMMARY_OFFSET, FIELD_SEP);
+        cur; cur = strtok(NULL, FIELD_SEP))
+    {
       /* Update the tags - O(n) search through the affected indices. */
       seprintf(file, FILE_MAX, TAGS_DIR"/%s", cur);
       if(ntx_replace(file, id, note) == 0)
@@ -437,7 +468,7 @@

 void ntx_del(char *id)
 {
-  char file[FILE_MAX], *buf, *ptr, *cur;
+  char file[FILE_MAX], *buf, *cur;

   seprintf(file, FILE_MAX, REFS_DIR"/%.2s", id);

@@ -445,10 +476,8 @@
   if(!(buf = ntx_find(file, id)))
     die("Unable to locate note %s in %s.", id, file);

-  for(cur = buf + SUMMARY_OFFSET; (ptr = strchr(cur, FIELD_SEP));
-      cur = ptr + 1) {
-    *ptr = '\0';
-
+  for(cur = strtok(buf + SUMMARY_OFFSET, FIELD_SEP);
+      cur; cur = strtok(NULL, FIELD_SEP)) {
     /* Delete the tags - O(n) search through the affected indices. */
     seprintf(file, FILE_MAX, TAGS_DIR"/%s", cur);
     if(ntx_replace(file, id, NULL) == 0)
@@ -481,17 +510,15 @@

     ntx_dclose(dir);
   } else { /* List all tags of a note. */
-    char file[FILE_MAX], *buf, *ptr, *cur;
+    char file[FILE_MAX], *buf, *cur;

     seprintf(file, FILE_MAX, REFS_DIR"/%.2s", id);
     if(!(buf = ntx_find(file, id)))
       die("Unable to locate note %s in %s.", id, file);

-    for(cur = buf + SUMMARY_OFFSET; (ptr = strchr(cur, FIELD_SEP));
-        cur = ptr + 1) {
-      *ptr = '\0';
+    for(cur = strtok(buf + SUMMARY_OFFSET, FIELD_SEP);
+        cur; cur = strtok(NULL, FIELD_SEP))
       puts(cur);
-    }

     release(buf);
   }
@@ -500,7 +527,8 @@
 void ntx_retag(char *id, char **tags)
 {
   char file[FILE_MAX], desc[SUMREC_LENGTH];
-  char *tmp, *next, *orig, **cur;
+  char **ntag, **otag, **otags;
+  char *buffer;

   /* Get the summary in case we need to write it. */
   seprintf(file, FILE_MAX, NOTES_DIR"/%s", id);
@@ -512,37 +540,47 @@

   /* Read in the original listing of tags for this file. */
   seprintf(file, FILE_MAX, REFS_DIR"/%.2s", id);
-  if(!(orig = ntx_find(file, id)))
+  if(!(buffer = ntx_find(file, id)))
     die("Unable to locate note %s in %s.", id, file);

+  /* Tokenize the original line. */
+  otags = strtokens(buffer + SUMMARY_OFFSET, FIELD_SEP);
+
   /* Add any tags which don't yet exist. */
-  for(cur = tags; *cur; cur++) {
-    if(!strstr(orig, *cur)) { /* Add the tag to the file. */
-      seprintf(file, FILE_MAX, TAGS_DIR"/%s", *cur);
+  for(ntag = tags; *ntag; ntag++) {
+    for(otag = otags; *otag; otag++)
+      if(strcmp(*ntag, *otag) == 0)
+        break;
+
+    if(!*otag) { /* Add the tag to the file. */
+      seprintf(file, FILE_MAX, TAGS_DIR"/%s", *ntag);
       ntx_append(file, desc);
     }
   }

   /* Remove any tags which don't exist any more. */
-  for(tmp = orig + SUMMARY_OFFSET; (next = strchr(tmp, FIELD_SEP));
-      tmp = next + 1) {
-    *next = '\0';
-    for(cur = tags; *cur; cur++) if(strcmp(*cur, tmp) == 0) break;
-
-    if(!*cur) { /* Remove any tags we didn't find. */
-      seprintf(file, FILE_MAX, TAGS_DIR"/%s", tmp);
+  for(otag = otags; *otag; otag++) {
+    for(ntag = tags; *ntag; ntag++)
+      if(strcmp(*otag, *ntag) == 0)
+        break;
+
+    if(!*ntag) { /* Remove deleted tag. */
+      seprintf(file, FILE_MAX, TAGS_DIR"/%s", *otag);
       if(ntx_replace(file, id, NULL) == 0)
         die("Unable to locate note %s in %s.", id, file);
     }
   }

+  release(otags);
+  release(buffer);
+
   /* Update the backreference with the new set of tags. */
-  tmp = ntx_tagstolist(id, tags);
+  buffer = ntx_tagstolist(id, tags);
   seprintf(file, FILE_MAX, REFS_DIR"/%.2s", id);
-  if(ntx_replace(file, id, tmp) == 0)
+  if(ntx_replace(file, id, buffer) == 0)
     die("Unable to locate note %s in %s.", id, file);

-  release(tmp);
+  release(buffer);
 }

 void ntx_usage(int retcode)


loader: Fix XDG path parsing

loader: Fix XDG path parsing

Fixes #1474

Fix path parsing code to handle leading and trailing
path separators.  Also handle contiguous path separators.
When encountering something like ::: in the path, the old
code would add multiple entries containing only the
relative part of the path (e.g., /vulkan.icd.d).

--- loader/loader.c
+++ loader/loader.c
@@ -2684,19 +2684,26 @@
         char *loc_write = loc;
 #if !defined(_WIN32)
         const char *loc_read;
+        size_t start, stop;

         loc_read = &xdgconfdirs[0];
-        for (const char *x = loc_read;; ++x) {
-            if (*x == PATH_SEPARATOR || *x == '\0') {
-                const size_t s = x - loc_read;
-                memcpy(loc_write, loc_read, s);
+        start = 0;
+        while (loc_read[start] != '\0') {
+            while (loc_read[start] == PATH_SEPARATOR) {
+                start++;
+            }
+            stop = start;
+            while (loc_read[stop] != PATH_SEPARATOR && loc_read[stop] != '\0') {
+                stop++;
+            }
+            const size_t s = stop - start;
+            if (s) {
+                memcpy(loc_write, &loc_read[start], s);
                 loc_write += s;
                 memcpy(loc_write, relative_location, rel_size);
                 loc_write += rel_size;
                 *loc_write++ = PATH_SEPARATOR;
-                if (*x == 0)
-                    break;
-                loc_read = ++x;
+                start = stop;
             }
         }

@@ -2715,19 +2722,26 @@
 #endif

         loc_read = &xdgdatadirs[0];
-        for (const char *x = loc_read;; ++x) {
-            if (*x == PATH_SEPARATOR || *x == '\0') {
-                const size_t s = x - loc_read;
-                memcpy(loc_write, loc_read, s);
+        start = 0;
+        while (loc_read[start] != '\0') {
+            while (loc_read[start] == PATH_SEPARATOR) {
+                start++;
+            }
+            stop = start;
+            while (loc_read[stop] != PATH_SEPARATOR && loc_read[stop] != '\0') {
+                stop++;
+            }
+            const size_t s = stop - start;
+            if (s) {
+                memcpy(loc_write, &loc_read[start], s);
                 loc_write += s;
                 memcpy(loc_write, relative_location, rel_size);
                 loc_write += rel_size;
                 *loc_write++ = PATH_SEPARATOR;
-                if (*x == 0)
-                    break;
-                loc_read = ++x;
-            }
-        }
+                start = stop;
+            }
+        }
+
         --loc_write;
 #else
         memcpy(loc_write, location, strlen(location));


Increase sbrk memory size.

Increase sbrk memory size.

Signed-off-by: Gerd Zellweger <1d6e1cf70ec6f9ab28d3ea4b27a49a77654d370e@gerdzellweger.com>

--- lib/posixcompat/sbrk.c
+++ lib/posixcompat/sbrk.c
@@ -12,7 +12,7 @@

 #if __SIZEOF_POINTER__ == 8
 //need lot of memory...
-#define SBRK_REGION_BYTES (1024*1024*8000ULL)
+#define SBRK_REGION_BYTES (1024*1024*200000ULL)
 #else // still huge, but slightly more achievable in a 32-bit address space!
 #define SBRK_REGION_BYTES (256 * 1024 * 1024)
 #endif


crypto: Fix bug in ng_api

crypto: Fix bug in ng_api

--- lib/crypto/c_src/api_ng.c
+++ lib/crypto/c_src/api_ng.c
@@ -218,18 +218,22 @@
             goto err;
         }
     }
-
-    if (!EVP_CipherInit_ex(ctx_res->ctx, NULL, NULL, key_bin.data, NULL, -1)) {
-        *return_term = EXCP_ERROR(env, "Can't initialize key");
-        goto err;
-    }
-
-    if (ivec_arg != atom_undefined) {
-        if (!EVP_CipherInit_ex(ctx_res->ctx, NULL, NULL, NULL, ivec_bin.data, -1)) {
-            *return_term = EXCP_ERROR(env, "Can't initialize iv");
-            goto err;
-        }
-    }
+    //    enif_fprintf(stderr, "%s:%u %T %T %u\r\n", __FILE__, __LINE__, cipher_arg, ivec_arg, ivec_len);
+    if (ivec_arg == atom_undefined || ivec_len == 0)
+        {
+            if (!EVP_CipherInit_ex(ctx_res->ctx, NULL, NULL, key_bin.data, NULL, -1)) {
+                *return_term = EXCP_ERROR(env, "Can't initialize key");
+                goto err;
+            }
+        }
+    else
+        if (!EVP_CipherInit_ex(ctx_res->ctx, NULL, NULL, key_bin.data, ivec_bin.data, -1))
+            {
+                *return_term = EXCP_ERROR(env, "Can't initialize key or iv");
+                goto err;
+            }
+
+    // enif_fprintf(stderr, "%s:%u\r\n", __FILE__, __LINE__);

     EVP_CIPHER_CTX_set_padding(ctx_res->ctx, 0);


adjust threshold

adjust threshold

--- src/tcpcopy/tc_session.c
+++ src/tcpcopy/tc_session.c
@@ -1283,6 +1283,11 @@
         return OBSOLETE;
     }

+    diff = cur - s->resp_last_recv_cont_time;
+    if (diff < 6) {
+        threshold = threshold << 1;
+    }
+
     diff = cur - s->req_last_send_cont_time;
     /* check if the session is idle for a long time */
     if (diff < 30) {


Fix bug in OpenSim parser function CStrToBool

--- src/chrono/utils/ChParserOpenSim.h
+++ src/chrono/utils/ChParserOpenSim.h
@@ -166,7 +166,7 @@
     }

     // Convert a lowercase string to a boolean
-    static inline bool CStrToBool(const char* string) { return stringStripCStr(string) == std::string("true") == 0; }
+    static inline bool CStrToBool(const char* string) { return stringStripCStr(string) == std::string("true"); }

     // Maps child fields of a body node to functions that handle said fields
     std::map<std::string, std::function<void(rapidxml::xml_node<>*, std::shared_ptr<ChBodyAuxRef>)>> function_table;


<rdar://problem/9185449> update version info for arm

git-svn-id: c199f293c43da69278bea8e88f92242bf3aa95f7@129386 91177308-0d34-0410-b5e6-96231b3b80d8

--- lib/apple_versioning.c
+++ lib/apple_versioning.c
@@ -143,6 +143,147 @@
 NOT_HERE_BEFORE_10_6(__trampoline_setup)
 #endif /* __ppc__ */

+#if __arm__
+   #define NOT_HERE_UNITL_AFTER_4_3(sym) \
+        extern const char sym##_tmp1 __asm("$ld$hide$os3.0$_" #sym ); \
+            __attribute__((visibility("default"))) const char sym##_tmp1 = 0; \
+        extern const char sym##_tmp2 __asm("$ld$hide$os3.1$_" #sym ); \
+            __attribute__((visibility("default"))) const char sym##_tmp2 = 0; \
+        extern const char sym##_tmp3 __asm("$ld$hide$os3.2$_" #sym ); \
+            __attribute__((visibility("default"))) const char sym##_tmp3 = 0; \
+        extern const char sym##_tmp4 __asm("$ld$hide$os4.0$_" #sym ); \
+            __attribute__((visibility("default"))) const char sym##_tmp4 = 0; \
+        extern const char sym##_tmp5 __asm("$ld$hide$os4.1$_" #sym ); \
+            __attribute__((visibility("default"))) const char sym##_tmp5 = 0; \
+        extern const char sym##_tmp6 __asm("$ld$hide$os4.2$_" #sym ); \
+            __attribute__((visibility("default"))) const char sym##_tmp6 = 0; \
+        extern const char sym##_tmp7 __asm("$ld$hide$os4.3$_" #sym ); \
+            __attribute__((visibility("default"))) const char sym##_tmp7 = 0;
+
+NOT_HERE_UNITL_AFTER_4_3(__absvdi2)
+NOT_HERE_UNITL_AFTER_4_3(__absvsi2)
+NOT_HERE_UNITL_AFTER_4_3(__adddf3)
+NOT_HERE_UNITL_AFTER_4_3(__adddf3vfp)
+NOT_HERE_UNITL_AFTER_4_3(__addsf3)
+NOT_HERE_UNITL_AFTER_4_3(__addsf3vfp)
+NOT_HERE_UNITL_AFTER_4_3(__addvdi3)
+NOT_HERE_UNITL_AFTER_4_3(__addvsi3)
+NOT_HERE_UNITL_AFTER_4_3(__ashldi3)
+NOT_HERE_UNITL_AFTER_4_3(__ashrdi3)
+NOT_HERE_UNITL_AFTER_4_3(__bswapdi2)
+NOT_HERE_UNITL_AFTER_4_3(__bswapsi2)
+NOT_HERE_UNITL_AFTER_4_3(__clzdi2)
+NOT_HERE_UNITL_AFTER_4_3(__clzsi2)
+NOT_HERE_UNITL_AFTER_4_3(__cmpdi2)
+NOT_HERE_UNITL_AFTER_4_3(__ctzdi2)
+NOT_HERE_UNITL_AFTER_4_3(__ctzsi2)
+NOT_HERE_UNITL_AFTER_4_3(__divdc3)
+NOT_HERE_UNITL_AFTER_4_3(__divdf3)
+NOT_HERE_UNITL_AFTER_4_3(__divdf3vfp)
+NOT_HERE_UNITL_AFTER_4_3(__divdi3)
+NOT_HERE_UNITL_AFTER_4_3(__divsc3)
+NOT_HERE_UNITL_AFTER_4_3(__divsf3)
+NOT_HERE_UNITL_AFTER_4_3(__divsf3vfp)
+NOT_HERE_UNITL_AFTER_4_3(__divsi3)
+NOT_HERE_UNITL_AFTER_4_3(__eqdf2)
+NOT_HERE_UNITL_AFTER_4_3(__eqdf2vfp)
+NOT_HERE_UNITL_AFTER_4_3(__eqsf2)
+NOT_HERE_UNITL_AFTER_4_3(__eqsf2vfp)
+NOT_HERE_UNITL_AFTER_4_3(__extendsfdf2)
+NOT_HERE_UNITL_AFTER_4_3(__extendsfdf2vfp)
+NOT_HERE_UNITL_AFTER_4_3(__ffsdi2)
+NOT_HERE_UNITL_AFTER_4_3(__fixdfdi)
+NOT_HERE_UNITL_AFTER_4_3(__fixdfsi)
+NOT_HERE_UNITL_AFTER_4_3(__fixdfsivfp)
+NOT_HERE_UNITL_AFTER_4_3(__fixsfdi)
+NOT_HERE_UNITL_AFTER_4_3(__fixsfsi)
+NOT_HERE_UNITL_AFTER_4_3(__fixsfsivfp)
+NOT_HERE_UNITL_AFTER_4_3(__fixunsdfdi)
+NOT_HERE_UNITL_AFTER_4_3(__fixunsdfsi)
+NOT_HERE_UNITL_AFTER_4_3(__fixunsdfsivfp)
+NOT_HERE_UNITL_AFTER_4_3(__fixunssfdi)
+NOT_HERE_UNITL_AFTER_4_3(__fixunssfsi)
+NOT_HERE_UNITL_AFTER_4_3(__fixunssfsivfp)
+NOT_HERE_UNITL_AFTER_4_3(__floatdidf)
+NOT_HERE_UNITL_AFTER_4_3(__floatdisf)
+NOT_HERE_UNITL_AFTER_4_3(__floatsidf)
+NOT_HERE_UNITL_AFTER_4_3(__floatsidfvfp)
+NOT_HERE_UNITL_AFTER_4_3(__floatsisf)
+NOT_HERE_UNITL_AFTER_4_3(__floatsisfvfp)
+NOT_HERE_UNITL_AFTER_4_3(__floatundidf)
+NOT_HERE_UNITL_AFTER_4_3(__floatundisf)
+NOT_HERE_UNITL_AFTER_4_3(__floatunsidf)
+NOT_HERE_UNITL_AFTER_4_3(__floatunsisf)
+NOT_HERE_UNITL_AFTER_4_3(__floatunssidfvfp)
+NOT_HERE_UNITL_AFTER_4_3(__floatunssisfvfp)
+NOT_HERE_UNITL_AFTER_4_3(__gedf2)
+NOT_HERE_UNITL_AFTER_4_3(__gedf2vfp)
+NOT_HERE_UNITL_AFTER_4_3(__gesf2)
+NOT_HERE_UNITL_AFTER_4_3(__gesf2vfp)
+NOT_HERE_UNITL_AFTER_4_3(__gtdf2)
+NOT_HERE_UNITL_AFTER_4_3(__gtdf2vfp)
+NOT_HERE_UNITL_AFTER_4_3(__gtsf2)
+NOT_HERE_UNITL_AFTER_4_3(__gtsf2vfp)
+NOT_HERE_UNITL_AFTER_4_3(__ledf2)
+NOT_HERE_UNITL_AFTER_4_3(__ledf2vfp)
+NOT_HERE_UNITL_AFTER_4_3(__lesf2)
+NOT_HERE_UNITL_AFTER_4_3(__lesf2vfp)
+NOT_HERE_UNITL_AFTER_4_3(__lshrdi3)
+NOT_HERE_UNITL_AFTER_4_3(__ltdf2)
+NOT_HERE_UNITL_AFTER_4_3(__ltdf2vfp)
+NOT_HERE_UNITL_AFTER_4_3(__ltsf2)
+NOT_HERE_UNITL_AFTER_4_3(__ltsf2vfp)
+NOT_HERE_UNITL_AFTER_4_3(__moddi3)
+NOT_HERE_UNITL_AFTER_4_3(__modsi3)
+NOT_HERE_UNITL_AFTER_4_3(__muldc3)
+NOT_HERE_UNITL_AFTER_4_3(__muldf3)
+NOT_HERE_UNITL_AFTER_4_3(__muldf3vfp)
+NOT_HERE_UNITL_AFTER_4_3(__muldi3)
+NOT_HERE_UNITL_AFTER_4_3(__mulsc3)
+NOT_HERE_UNITL_AFTER_4_3(__mulsf3)
+NOT_HERE_UNITL_AFTER_4_3(__mulsf3vfp)
+NOT_HERE_UNITL_AFTER_4_3(__mulvdi3)
+NOT_HERE_UNITL_AFTER_4_3(__mulvsi3)
+NOT_HERE_UNITL_AFTER_4_3(__nedf2)
+NOT_HERE_UNITL_AFTER_4_3(__nedf2vfp)
+NOT_HERE_UNITL_AFTER_4_3(__negdi2)
+NOT_HERE_UNITL_AFTER_4_3(__negvdi2)
+NOT_HERE_UNITL_AFTER_4_3(__negvsi2)
+NOT_HERE_UNITL_AFTER_4_3(__nesf2)
+NOT_HERE_UNITL_AFTER_4_3(__nesf2vfp)
+NOT_HERE_UNITL_AFTER_4_3(__paritydi2)
+NOT_HERE_UNITL_AFTER_4_3(__paritysi2)
+NOT_HERE_UNITL_AFTER_4_3(__popcountdi2)
+NOT_HERE_UNITL_AFTER_4_3(__popcountsi2)
+NOT_HERE_UNITL_AFTER_4_3(__powidf2)
+NOT_HERE_UNITL_AFTER_4_3(__powisf2)
+NOT_HERE_UNITL_AFTER_4_3(__subdf3)
+NOT_HERE_UNITL_AFTER_4_3(__subdf3vfp)
+NOT_HERE_UNITL_AFTER_4_3(__subsf3)
+NOT_HERE_UNITL_AFTER_4_3(__subsf3vfp)
+NOT_HERE_UNITL_AFTER_4_3(__subvdi3)
+NOT_HERE_UNITL_AFTER_4_3(__subvsi3)
+NOT_HERE_UNITL_AFTER_4_3(__truncdfsf2)
+NOT_HERE_UNITL_AFTER_4_3(__truncdfsf2vfp)
+NOT_HERE_UNITL_AFTER_4_3(__ucmpdi2)
+NOT_HERE_UNITL_AFTER_4_3(__udivdi3)
+NOT_HERE_UNITL_AFTER_4_3(__udivmoddi4)
+NOT_HERE_UNITL_AFTER_4_3(__udivsi3)
+NOT_HERE_UNITL_AFTER_4_3(__umoddi3)
+NOT_HERE_UNITL_AFTER_4_3(__umodsi3)
+NOT_HERE_UNITL_AFTER_4_3(__unorddf2)
+NOT_HERE_UNITL_AFTER_4_3(__unorddf2vfp)
+NOT_HERE_UNITL_AFTER_4_3(__unordsf2)
+NOT_HERE_UNITL_AFTER_4_3(__unordsf2vfp)
+
+NOT_HERE_UNITL_AFTER_4_3(__divmodsi4)
+NOT_HERE_UNITL_AFTER_4_3(__udivmodsi4)
+#endif
+
+
+
+
+
 #else /* !__APPLE__ */

 extern int avoid_empty_file;


Add comments for doxygen documentation regroupement. Rename some members


epoll: fix epoll's own poll

epoll: fix epoll's own poll

Fix a bug inside the epoll's f_op->poll() code, that returns POLLIN even
though there are no actual ready monitored fds.  The bug shows up if you
add an epoll fd inside another fd container (poll, select, epoll).

The problem is that callback-based wake ups used by epoll does not carry
(patches will follow, to fix this) any information about the events that
actually happened.  So the callback code, since it can't call the file*
->poll() inside the callback, chains the file* into a ready-list.

So, suppose you added an fd with EPOLLOUT only, and some data shows up on
the fd, the file* mapped by the fd will be added into the ready-list (via
wakeup callback).  During normal epoll_wait() use, this condition is
sorted out at the time we're actually able to call the file*'s
f_op->poll().

Inside the old epoll's f_op->poll() though, only a quick check
!list_empty(ready-list) was performed, and this could have led to
reporting POLLIN even though no ready fds would show up at a following
epoll_wait().  In order to correctly report the ready status for an epoll
fd, the ready-list must be checked to see if any really available fd+event
would be ready in a following epoll_wait().

Operation (calling f_op->poll() from inside f_op->poll()) that, like wake
ups, must be handled with care because of the fact that epoll fds can be
added to other epoll fds.

Test code:

/*
 *  epoll_test by Davide Libenzi (Simple code to test epoll internals)
 *  Copyright (C) 2008  Davide Libenzi
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 *  Davide Libenzi <91df8000b8dca80eb036dde93edf593d4a91414e@xmailserver.org>
 *
 */

#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <signal.h>
#include <limits.h>
#include <poll.h>
#include <sys/epoll.h>
#include <sys/wait.h>

#define EPWAIT_TIMEO	(1 * 1000)
#ifndef POLLRDHUP
#define POLLRDHUP 0x2000
#endif

#define EPOLL_MAX_CHAIN	100L

#define EPOLL_TF_LOOP (1 << 0)

struct epoll_test_cfg {
	long size;
	long flags;
};

static int xepoll_create(int n) {
	int epfd;

	if ((epfd = epoll_create(n)) == -1) {
		perror("epoll_create");
		exit(2);
	}

	return epfd;
}

static void xepoll_ctl(int epfd, int cmd, int fd, struct epoll_event *evt) {
	if (epoll_ctl(epfd, cmd, fd, evt) < 0) {
		perror("epoll_ctl");
		exit(3);
	}
}

static void xpipe(int *fds) {
	if (pipe(fds)) {
		perror("pipe");
		exit(4);
	}
}

static pid_t xfork(void) {
	pid_t pid;

	if ((pid = fork()) == (pid_t) -1) {
		perror("pipe");
		exit(5);
	}

	return pid;
}

static int run_forked_proc(int (*proc)(void *), void *data) {
	int status;
	pid_t pid;

	if ((pid = xfork()) == 0)
		exit((*proc)(data));
	if (waitpid(pid, &status, 0) != pid) {
		perror("waitpid");
		return -1;
	}

	return WIFEXITED(status) ? WEXITSTATUS(status): -2;
}

static int check_events(int fd, int timeo) {
	struct pollfd pfd;

	fprintf(stdout, "Checking events for fd %d\n", fd);
	memset(&pfd, 0, sizeof(pfd));
	pfd.fd = fd;
	pfd.events = POLLIN | POLLOUT;
	if (poll(&pfd, 1, timeo) < 0) {
		perror("poll()");
		return 0;
	}
	if (pfd.revents & POLLIN)
		fprintf(stdout, "\tPOLLIN\n");
	if (pfd.revents & POLLOUT)
		fprintf(stdout, "\tPOLLOUT\n");
	if (pfd.revents & POLLERR)
		fprintf(stdout, "\tPOLLERR\n");
	if (pfd.revents & POLLHUP)
		fprintf(stdout, "\tPOLLHUP\n");
	if (pfd.revents & POLLRDHUP)
		fprintf(stdout, "\tPOLLRDHUP\n");

	return pfd.revents;
}

static int epoll_test_tty(void *data) {
	int epfd, ifd = fileno(stdin), res;
	struct epoll_event evt;

	if (check_events(ifd, 0) != POLLOUT) {
		fprintf(stderr, "Something is cooking on STDIN (%d)\n", ifd);
		return 1;
	}
	epfd = xepoll_create(1);
	fprintf(stdout, "Created epoll fd (%d)\n", epfd);
	memset(&evt, 0, sizeof(evt));
	evt.events = EPOLLIN;
	xepoll_ctl(epfd, EPOLL_CTL_ADD, ifd, &evt);
	if (check_events(epfd, 0) & POLLIN) {
		res = epoll_wait(epfd, &evt, 1, 0);
		if (res == 0) {
			fprintf(stderr, "Epoll fd (%d) is ready when it shouldn't!\n",
				epfd);
			return 2;
		}
	}

	return 0;
}

static int epoll_wakeup_chain(void *data) {
	struct epoll_test_cfg *tcfg = data;
	int i, res, epfd, bfd, nfd, pfds[2];
	pid_t pid;
	struct epoll_event evt;

	memset(&evt, 0, sizeof(evt));
	evt.events = EPOLLIN;

	epfd = bfd = xepoll_create(1);

	for (i = 0; i < tcfg->size; i++) {
		nfd = xepoll_create(1);
		xepoll_ctl(bfd, EPOLL_CTL_ADD, nfd, &evt);
		bfd = nfd;
	}
	xpipe(pfds);
	if (tcfg->flags & EPOLL_TF_LOOP)
	{
		xepoll_ctl(bfd, EPOLL_CTL_ADD, epfd, &evt);
		/*
		 * If we're testing for loop, we want that the wakeup
		 * triggered by the write to the pipe done in the child
		 * process, triggers a fake event. So we add the pipe
		 * read size with EPOLLOUT events. This will trigger
		 * an addition to the ready-list, but no real events
		 * will be there. The the epoll kernel code will proceed
		 * in calling f_op->poll() of the epfd, triggering the
		 * loop we want to test.
		 */
		evt.events = EPOLLOUT;
	}
	xepoll_ctl(bfd, EPOLL_CTL_ADD, pfds[0], &evt);

	/*
	 * The pipe write must come after the poll(2) call inside
	 * check_events(). This tests the nested wakeup code in
	 * fs/eventpoll.c:ep_poll_safewake()
	 * By having the check_events() (hence poll(2)) happens first,
	 * we have poll wait queue filled up, and the write(2) in the
	 * child will trigger the wakeup chain.
	 */
	if ((pid = xfork()) == 0) {
		sleep(1);
		write(pfds[1], "w", 1);
		exit(0);
	}

	res = check_events(epfd, 2000) & POLLIN;

	if (waitpid(pid, NULL, 0) != pid) {
		perror("waitpid");
		return -1;
	}

	return res;
}

static int epoll_poll_chain(void *data) {
	struct epoll_test_cfg *tcfg = data;
	int i, res, epfd, bfd, nfd, pfds[2];
	pid_t pid;
	struct epoll_event evt;

	memset(&evt, 0, sizeof(evt));
	evt.events = EPOLLIN;

	epfd = bfd = xepoll_create(1);

	for (i = 0; i < tcfg->size; i++) {
		nfd = xepoll_create(1);
		xepoll_ctl(bfd, EPOLL_CTL_ADD, nfd, &evt);
		bfd = nfd;
	}
	xpipe(pfds);
	if (tcfg->flags & EPOLL_TF_LOOP)
	{
		xepoll_ctl(bfd, EPOLL_CTL_ADD, epfd, &evt);
		/*
		 * If we're testing for loop, we want that the wakeup
		 * triggered by the write to the pipe done in the child
		 * process, triggers a fake event. So we add the pipe
		 * read size with EPOLLOUT events. This will trigger
		 * an addition to the ready-list, but no real events
		 * will be there. The the epoll kernel code will proceed
		 * in calling f_op->poll() of the epfd, triggering the
		 * loop we want to test.
		 */
		evt.events = EPOLLOUT;
	}
	xepoll_ctl(bfd, EPOLL_CTL_ADD, pfds[0], &evt);

	/*
	 * The pipe write mush come before the poll(2) call inside
	 * check_events(). This tests the nested f_op->poll calls code in
	 * fs/eventpoll.c:ep_eventpoll_poll()
	 * By having the pipe write(2) happen first, we make the kernel
	 * epoll code to load the ready lists, and the following poll(2)
	 * done inside check_events() will test nested poll code in
	 * ep_eventpoll_poll().
	 */
	if ((pid = xfork()) == 0) {
		write(pfds[1], "w", 1);
		exit(0);
	}
	sleep(1);
	res = check_events(epfd, 1000) & POLLIN;

	if (waitpid(pid, NULL, 0) != pid) {
		perror("waitpid");
		return -1;
	}

	return res;
}

int main(int ac, char **av) {
	int error;
	struct epoll_test_cfg tcfg;

	fprintf(stdout, "\n********** Testing TTY events\n");
	error = run_forked_proc(epoll_test_tty, NULL);
	fprintf(stdout, error == 0 ?
		"********** OK\n": "********** FAIL (%d)\n", error);

	tcfg.size = 3;
	tcfg.flags = 0;
	fprintf(stdout, "\n********** Testing short wakeup chain\n");
	error = run_forked_proc(epoll_wakeup_chain, &tcfg);
	fprintf(stdout, error == POLLIN ?
		"********** OK\n": "********** FAIL (%d)\n", error);

	tcfg.size = EPOLL_MAX_CHAIN;
	tcfg.flags = 0;
	fprintf(stdout, "\n********** Testing long wakeup chain (HOLD ON)\n");
	error = run_forked_proc(epoll_wakeup_chain, &tcfg);
	fprintf(stdout, error == 0 ?
		"********** OK\n": "********** FAIL (%d)\n", error);

	tcfg.size = 3;
	tcfg.flags = 0;
	fprintf(stdout, "\n********** Testing short poll chain\n");
	error = run_forked_proc(epoll_poll_chain, &tcfg);
	fprintf(stdout, error == POLLIN ?
		"********** OK\n": "********** FAIL (%d)\n", error);

	tcfg.size = EPOLL_MAX_CHAIN;
	tcfg.flags = 0;
	fprintf(stdout, "\n********** Testing long poll chain (HOLD ON)\n");
	error = run_forked_proc(epoll_poll_chain, &tcfg);
	fprintf(stdout, error == 0 ?
		"********** OK\n": "********** FAIL (%d)\n", error);

	tcfg.size = 3;
	tcfg.flags = EPOLL_TF_LOOP;
	fprintf(stdout, "\n********** Testing loopy wakeup chain (HOLD ON)\n");
	error = run_forked_proc(epoll_wakeup_chain, &tcfg);
	fprintf(stdout, error == 0 ?
		"********** OK\n": "********** FAIL (%d)\n", error);

	tcfg.size = 3;
	tcfg.flags = EPOLL_TF_LOOP;
	fprintf(stdout, "\n********** Testing loopy poll chain (HOLD ON)\n");
	error = run_forked_proc(epoll_poll_chain, &tcfg);
	fprintf(stdout, error == 0 ?
		"********** OK\n": "********** FAIL (%d)\n", error);

	return 0;
}

Signed-off-by: Davide Libenzi <91df8000b8dca80eb036dde93edf593d4a91414e@xmailserver.org>
Cc: Pavel Pisa <8d20fe7a98d042d9ba77cb8ddc5c00c7726b2e8b@cmp.felk.cvut.cz>
Signed-off-by: Andrew Morton <5c1e68b099950c134891f0b6e179498a8ebe9cf9@linux-foundation.org>
Signed-off-by: Linus Torvalds <69652caca27c8b940640ad396ab71f93cacec34f@linux-foundation.org>

--- fs/eventpoll.c
+++ fs/eventpoll.c
@@ -1,6 +1,6 @@
 /*
- *  fs/eventpoll.c (Efficent event polling implementation)
- *  Copyright (C) 2001,...,2007	 Davide Libenzi
+ *  fs/eventpoll.c (Efficient event retrieval implementation)
+ *  Copyright (C) 2001,...,2009	 Davide Libenzi
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -92,8 +92,8 @@
 /* Epoll private bits inside the event mask */
 #define EP_PRIVATE_BITS (EPOLLONESHOT | EPOLLET)

-/* Maximum number of poll wake up nests we are allowing */
-#define EP_MAX_POLLWAKE_NESTS 4
+/* Maximum number of nesting allowed inside epoll sets */
+#define EP_MAX_NESTS 4

 /* Maximum msec timeout value storeable in a long int */
 #define EP_MAX_MSTIMEO min(1000ULL * MAX_SCHEDULE_TIMEOUT / HZ, (LONG_MAX - 999ULL) / HZ)
@@ -110,24 +110,21 @@
 };

 /*
- * Node that is linked into the "wake_task_list" member of the "struct poll_safewake".
- * It is used to keep track on all tasks that are currently inside the wake_up() code
- * to 1) short-circuit the one coming from the same task and same wait queue head
- * (loop) 2) allow a maximum number of epoll descriptors inclusion nesting
- * 3) let go the ones coming from other tasks.
- */
-struct wake_task_node {
+ * Structure used to track possible nested calls, for too deep recursions
+ * and loop cycles.
+ */
+struct nested_call_node {
 	struct list_head llink;
 	struct task_struct *task;
-	wait_queue_head_t *wq;
+	void *cookie;
 };

 /*
- * This is used to implement the safe poll wake up avoiding to reenter
- * the poll callback from inside wake_up().
- */
-struct poll_safewake {
-	struct list_head wake_task_list;
+ * This structure is used as collector for nested calls, to check for
+ * maximum recursion dept and loop cycles.
+ */
+struct nested_calls {
+	struct list_head tasks_call_list;
 	spinlock_t lock;
 };

@@ -231,6 +228,12 @@
 	struct epitem *epi;
 };

+/* Used by the ep_send_events() function as callback private data */
+struct ep_send_events_data {
+	int maxevents;
+	struct epoll_event __user *events;
+};
+
 /*
  * Configuration options available inside /proc/sys/fs/epoll/
  */
@@ -242,8 +245,11 @@
  */
 static DEFINE_MUTEX(epmutex);

-/* Safe wake up implementation */
-static struct poll_safewake psw;
+/* Used for safe wake up implementation */
+static struct nested_calls poll_safewake_ncalls;
+
+/* Used to call file's f_op->poll() under the nested calls boundaries */
+static struct nested_calls poll_readywalk_ncalls;

 /* Slab cache used to allocate "struct epitem" */
 static struct kmem_cache *epi_cache __read_mostly;
@@ -312,11 +318,80 @@
 }

 /* Initialize the poll safe wake up structure */
-static void ep_poll_safewake_init(struct poll_safewake *psw)
-{
-
-	INIT_LIST_HEAD(&psw->wake_task_list);
-	spin_lock_init(&psw->lock);
+static void ep_nested_calls_init(struct nested_calls *ncalls)
+{
+	INIT_LIST_HEAD(&ncalls->tasks_call_list);
+	spin_lock_init(&ncalls->lock);
+}
+
+/**
+ * ep_call_nested - Perform a bound (possibly) nested call, by checking
+ *                  that the recursion limit is not exceeded, and that
+ *                  the same nested call (by the meaning of same cookie) is
+ *                  no re-entered.
+ *
+ * @ncalls: Pointer to the nested_calls structure to be used for this call.
+ * @max_nests: Maximum number of allowed nesting calls.
+ * @nproc: Nested call core function pointer.
+ * @priv: Opaque data to be passed to the @nproc callback.
+ * @cookie: Cookie to be used to identify this nested call.
+ *
+ * Returns: Returns the code returned by the @nproc callback, or -1 if
+ *          the maximum recursion limit has been exceeded.
+ */
+static int ep_call_nested(struct nested_calls *ncalls, int max_nests,
+			  int (*nproc)(void *, void *, int), void *priv,
+			  void *cookie)
+{
+	int error, call_nests = 0;
+	unsigned long flags;
+	struct task_struct *this_task = current;
+	struct list_head *lsthead = &ncalls->tasks_call_list;
+	struct nested_call_node *tncur;
+	struct nested_call_node tnode;
+
+	spin_lock_irqsave(&ncalls->lock, flags);
+
+	/*
+	 * Try to see if the current task is already inside this wakeup call.
+	 * We use a list here, since the population inside this set is always
+	 * very much limited.
+	 */
+	list_for_each_entry(tncur, lsthead, llink) {
+		if (tncur->task == this_task &&
+		    (tncur->cookie == cookie || ++call_nests > max_nests)) {
+			/*
+			 * Ops ... loop detected or maximum nest level reached.
+			 * We abort this wake by breaking the cycle itself.
+			 */
+			spin_unlock_irqrestore(&ncalls->lock, flags);
+
+			return -1;
+		}
+	}
+
+	/* Add the current task and cookie to the list */
+	tnode.task = this_task;
+	tnode.cookie = cookie;
+	list_add(&tnode.llink, lsthead);
+
+	spin_unlock_irqrestore(&ncalls->lock, flags);
+
+	/* Call the nested function */
+	error = (*nproc)(priv, cookie, call_nests);
+
+	/* Remove the current task from the list */
+	spin_lock_irqsave(&ncalls->lock, flags);
+	list_del(&tnode.llink);
+	spin_unlock_irqrestore(&ncalls->lock, flags);
+
+	return error;
+}
+
+static int ep_poll_wakeup_proc(void *priv, void *cookie, int call_nests)
+{
+	wake_up_nested((wait_queue_head_t *) cookie, 1 + call_nests);
+	return 0;
 }

 /*
@@ -324,52 +399,15 @@
  * with the new callback'd wake up system, it is possible that the
  * poll callback is reentered from inside the call to wake_up() done
  * on the poll wait queue head. The rule is that we cannot reenter the
- * wake up code from the same task more than EP_MAX_POLLWAKE_NESTS times,
+ * wake up code from the same task more than EP_MAX_NESTS times,
  * and we cannot reenter the same wait queue head at all. This will
  * enable to have a hierarchy of epoll file descriptor of no more than
- * EP_MAX_POLLWAKE_NESTS deep. We need the irq version of the spin lock
- * because this one gets called by the poll callback, that in turn is called
- * from inside a wake_up(), that might be called from irq context.
- */
-static void ep_poll_safewake(struct poll_safewake *psw, wait_queue_head_t *wq)
-{
-	int wake_nests = 0;
-	unsigned long flags;
-	struct task_struct *this_task = current;
-	struct list_head *lsthead = &psw->wake_task_list;
-	struct wake_task_node *tncur;
-	struct wake_task_node tnode;
-
-	spin_lock_irqsave(&psw->lock, flags);
-
-	/* Try to see if the current task is already inside this wakeup call */
-	list_for_each_entry(tncur, lsthead, llink) {
-
-		if (tncur->wq == wq ||
-		    (tncur->task == this_task && ++wake_nests > EP_MAX_POLLWAKE_NESTS)) {
-			/*
-			 * Ops ... loop detected or maximum nest level reached.
-			 * We abort this wake by breaking the cycle itself.
-			 */
-			spin_unlock_irqrestore(&psw->lock, flags);
-			return;
-		}
-	}
-
-	/* Add the current task to the list */
-	tnode.task = this_task;
-	tnode.wq = wq;
-	list_add(&tnode.llink, lsthead);
-
-	spin_unlock_irqrestore(&psw->lock, flags);
-
-	/* Do really wake up now */
-	wake_up_nested(wq, 1 + wake_nests);
-
-	/* Remove the current task from the list */
-	spin_lock_irqsave(&psw->lock, flags);
-	list_del(&tnode.llink);
-	spin_unlock_irqrestore(&psw->lock, flags);
+ * EP_MAX_NESTS deep.
+ */
+static void ep_poll_safewake(wait_queue_head_t *wq)
+{
+	ep_call_nested(&poll_safewake_ncalls, EP_MAX_NESTS,
+		       ep_poll_wakeup_proc, NULL, wq);
 }

 /*
@@ -395,6 +433,104 @@
 			kmem_cache_free(pwq_cache, pwq);
 		}
 	}
+}
+
+/**
+ * ep_scan_ready_list - Scans the ready list in a way that makes possible for
+ *                      the scan code, to call f_op->poll(). Also allows for
+ *                      O(NumReady) performance.
+ *
+ * @ep: Pointer to the epoll private data structure.
+ * @sproc: Pointer to the scan callback.
+ * @priv: Private opaque data passed to the @sproc callback.
+ *
+ * Returns: The same integer error code returned by the @sproc callback.
+ */
+static int ep_scan_ready_list(struct eventpoll *ep,
+			      int (*sproc)(struct eventpoll *,
+					   struct list_head *, void *),
+			      void *priv)
+{
+	int error, pwake = 0;
+	unsigned long flags;
+	struct epitem *epi, *nepi;
+	struct list_head txlist;
+
+	INIT_LIST_HEAD(&txlist);
+
+	/*
+	 * We need to lock this because we could be hit by
+	 * eventpoll_release_file() and epoll_ctl(EPOLL_CTL_DEL).
+	 */
+	mutex_lock(&ep->mtx);
+
+	/*
+	 * Steal the ready list, and re-init the original one to the
+	 * empty list. Also, set ep->ovflist to NULL so that events
+	 * happening while looping w/out locks, are not lost. We cannot
+	 * have the poll callback to queue directly on ep->rdllist,
+	 * because we want the "sproc" callback to be able to do it
+	 * in a lockless way.
+	 */
+	spin_lock_irqsave(&ep->lock, flags);
+	list_splice(&ep->rdllist, &txlist);
+	INIT_LIST_HEAD(&ep->rdllist);
+	ep->ovflist = NULL;
+	spin_unlock_irqrestore(&ep->lock, flags);
+
+	/*
+	 * Now call the callback function.
+	 */
+	error = (*sproc)(ep, &txlist, priv);
+
+	spin_lock_irqsave(&ep->lock, flags);
+	/*
+	 * During the time we spent inside the "sproc" callback, some
+	 * other events might have been queued by the poll callback.
+	 * We re-insert them inside the main ready-list here.
+	 */
+	for (nepi = ep->ovflist; (epi = nepi) != NULL;
+	     nepi = epi->next, epi->next = EP_UNACTIVE_PTR) {
+		/*
+		 * We need to check if the item is already in the list.
+		 * During the "sproc" callback execution time, items are
+		 * queued into ->ovflist but the "txlist" might already
+		 * contain them, and the list_splice() below takes care of them.
+		 */
+		if (!ep_is_linked(&epi->rdllink))
+			list_add_tail(&epi->rdllink, &ep->rdllist);
+	}
+	/*
+	 * We need to set back ep->ovflist to EP_UNACTIVE_PTR, so that after
+	 * releasing the lock, events will be queued in the normal way inside
+	 * ep->rdllist.
+	 */
+	ep->ovflist = EP_UNACTIVE_PTR;
+
+	/*
+	 * Quickly re-inject items left on "txlist".
+	 */
+	list_splice(&txlist, &ep->rdllist);
+
+	if (!list_empty(&ep->rdllist)) {
+		/*
+		 * Wake up (if active) both the eventpoll wait list and the ->poll()
+		 * wait list (delayed after we release the lock).
+		 */
+		if (waitqueue_active(&ep->wq))
+			wake_up_locked(&ep->wq);
+		if (waitqueue_active(&ep->poll_wait))
+			pwake++;
+	}
+	spin_unlock_irqrestore(&ep->lock, flags);
+
+	mutex_unlock(&ep->mtx);
+
+	/* We have to call this outside the lock */
+	if (pwake)
+		ep_poll_safewake(&ep->poll_wait);
+
+	return error;
 }

 /*
@@ -447,7 +583,7 @@

 	/* We need to release all tasks waiting for these file */
 	if (waitqueue_active(&ep->poll_wait))
-		ep_poll_safewake(&psw, &ep->poll_wait);
+		ep_poll_safewake(&ep->poll_wait);

 	/*
 	 * We need to lock this because we could be hit by
@@ -496,22 +632,49 @@
 	return 0;
 }

+static int ep_read_events_proc(struct eventpoll *ep, struct list_head *head, void *priv)
+{
+	struct epitem *epi, *tmp;
+
+	list_for_each_entry_safe(epi, tmp, head, rdllink) {
+		if (epi->ffd.file->f_op->poll(epi->ffd.file, NULL) &
+		    epi->event.events)
+			return POLLIN | POLLRDNORM;
+		else
+			/*
+			 * Item has been dropped into the ready list by the poll
+			 * callback, but it's not actually ready, as far as
+			 * caller requested events goes. We can remove it here.
+			 */
+			list_del_init(&epi->rdllink);
+	}
+
+	return 0;
+}
+
+static int ep_poll_readyevents_proc(void *priv, void *cookie, int call_nests)
+{
+	return ep_scan_ready_list(priv, ep_read_events_proc, NULL);
+}
+
 static unsigned int ep_eventpoll_poll(struct file *file, poll_table *wait)
 {
-	unsigned int pollflags = 0;
-	unsigned long flags;
+	int pollflags;
 	struct eventpoll *ep = file->private_data;

 	/* Insert inside our poll wait queue */
 	poll_wait(file, &ep->poll_wait, wait);

-	/* Check our condition */
-	spin_lock_irqsave(&ep->lock, flags);
-	if (!list_empty(&ep->rdllist))
-		pollflags = POLLIN | POLLRDNORM;
-	spin_unlock_irqrestore(&ep->lock, flags);
-
-	return pollflags;
+	/*
+	 * Proceed to find out if wanted events are really available inside
+	 * the ready list. This need to be done under ep_call_nested()
+	 * supervision, since the call to f_op->poll() done on listed files
+	 * could re-enter here.
+	 */
+	pollflags = ep_call_nested(&poll_readywalk_ncalls, EP_MAX_NESTS,
+				   ep_poll_readyevents_proc, ep, ep);
+
+	return pollflags != -1 ? pollflags: 0;
 }

 /* File callbacks that implement the eventpoll file behaviour */
@@ -541,7 +704,7 @@
 	 * We don't want to get "file->f_lock" because it is not
 	 * necessary. It is not necessary because we're in the "struct file"
 	 * cleanup path, and this means that noone is using this file anymore.
-	 * So, for example, epoll_ctl() cannot hit here sicne if we reach this
+	 * So, for example, epoll_ctl() cannot hit here since if we reach this
 	 * point, the file counter already went to zero and fget() would fail.
 	 * The only hit might come from ep_free() but by holding the mutex
 	 * will correctly serialize the operation. We do need to acquire
@@ -670,12 +833,9 @@
 	}

 	/* If this file is already in the ready list we exit soon */
-	if (ep_is_linked(&epi->rdllink))
-		goto is_linked;
-
-	list_add_tail(&epi->rdllink, &ep->rdllist);
-
-is_linked:
+	if (!ep_is_linked(&epi->rdllink))
+		list_add_tail(&epi->rdllink, &ep->rdllist);
+
 	/*
 	 * Wake up ( if active ) both the eventpoll wait list and the ->poll()
 	 * wait list.
@@ -690,7 +850,7 @@

 	/* We have to call this outside the lock */
 	if (pwake)
-		ep_poll_safewake(&psw, &ep->poll_wait);
+		ep_poll_safewake(&ep->poll_wait);

 	return 1;
 }
@@ -712,10 +872,9 @@
 		add_wait_queue(whead, &pwq->wait);
 		list_add_tail(&pwq->llink, &epi->pwqlist);
 		epi->nwait++;
-	} else {
+	} else
 		/* We have to signal that an error occurred */
 		epi->nwait = -1;
-	}
 }

 static void ep_rbtree_insert(struct eventpoll *ep, struct epitem *epi)
@@ -817,7 +976,7 @@

 	/* We have to call this outside the lock */
 	if (pwake)
-		ep_poll_safewake(&psw, &ep->poll_wait);
+		ep_poll_safewake(&ep->poll_wait);

 	DNPRINTK(3, (KERN_INFO "[%p] eventpoll: ep_insert(%p, %p, %d)\n",
 		     current, ep, tfile, fd));
@@ -891,137 +1050,74 @@

 	/* We have to call this outside the lock */
 	if (pwake)
-		ep_poll_safewake(&psw, &ep->poll_wait);
+		ep_poll_safewake(&ep->poll_wait);

 	return 0;
+}
+
+static int ep_send_events_proc(struct eventpoll *ep, struct list_head *head, void *priv)
+{
+	struct ep_send_events_data *esed = priv;
+	int eventcnt;
+  	unsigned int revents;
+	struct epitem *epi;
+	struct epoll_event __user *uevent;
+
+  	/*
+	 * We can loop without lock because we are passed a task private list.
+	 * Items cannot vanish during the loop because ep_scan_ready_list() is
+	 * holding "mtx" during this call.
+  	 */
+	for (eventcnt = 0, uevent = esed->events;
+	     !list_empty(head) && eventcnt < esed->maxevents;) {
+		epi = list_first_entry(head, struct epitem, rdllink);
+
+		list_del_init(&epi->rdllink);
+
+  		revents = epi->ffd.file->f_op->poll(epi->ffd.file, NULL) &
+  			epi->event.events;
+
+  		/*
+		 * If the event mask intersect the caller-requested one,
+		 * deliver the event to userspace. Again, ep_scan_ready_list()
+		 * is holding "mtx", so no operations coming from userspace
+		 * can change the item.
+  		 */
+  		if (revents) {
+			if (__put_user(revents, &uevent->events) ||
+			    __put_user(epi->event.data, &uevent->data))
+				return eventcnt ? eventcnt: -EFAULT;
+  			eventcnt++;
+			uevent++;
+  			if (epi->event.events & EPOLLONESHOT)
+  				epi->event.events &= EP_PRIVATE_BITS;
+  			else if (!(epi->event.events & EPOLLET))
+  				/*
+				 * If this file has been added with Level Trigger
+				 * mode, we need to insert back inside the ready
+				 * list, so that the next call to epoll_wait()
+				 * will check again the events availability.
+  				 * At this point, noone can insert into ep->rdllist
+  				 * besides us. The epoll_ctl() callers are locked
+				 * out by ep_scan_ready_list() holding "mtx" and
+				 * the poll callback will queue them in ep->ovflist.
+  				 */
+  				list_add_tail(&epi->rdllink, &ep->rdllist);
+  		}
+  	}
+
+	return eventcnt;
 }

 static int ep_send_events(struct eventpoll *ep, struct epoll_event __user *events,
 			  int maxevents)
 {
-	int eventcnt, error = -EFAULT, pwake = 0;
-	unsigned int revents;
-	unsigned long flags;
-	struct epitem *epi, *nepi;
-	struct list_head txlist;
-
-	INIT_LIST_HEAD(&txlist);
-
-	/*
-	 * We need to lock this because we could be hit by
-	 * eventpoll_release_file() and epoll_ctl(EPOLL_CTL_DEL).
-	 */
-	mutex_lock(&ep->mtx);
-
-	/*
-	 * Steal the ready list, and re-init the original one to the
-	 * empty list. Also, set ep->ovflist to NULL so that events
-	 * happening while looping w/out locks, are not lost. We cannot
-	 * have the poll callback to queue directly on ep->rdllist,
-	 * because we are doing it in the loop below, in a lockless way.
-	 */
-	spin_lock_irqsave(&ep->lock, flags);
-	list_splice(&ep->rdllist, &txlist);
-	INIT_LIST_HEAD(&ep->rdllist);
-	ep->ovflist = NULL;
-	spin_unlock_irqrestore(&ep->lock, flags);
-
-	/*
-	 * We can loop without lock because this is a task private list.
-	 * We just splice'd out the ep->rdllist in ep_collect_ready_items().
-	 * Items cannot vanish during the loop because we are holding "mtx".
-	 */
-	for (eventcnt = 0; !list_empty(&txlist) && eventcnt < maxevents;) {
-		epi = list_first_entry(&txlist, struct epitem, rdllink);
-
-		list_del_init(&epi->rdllink);
-
-		/*
-		 * Get the ready file event set. We can safely use the file
-		 * because we are holding the "mtx" and this will guarantee
-		 * that both the file and the item will not vanish.
-		 */
-		revents = epi->ffd.file->f_op->poll(epi->ffd.file, NULL);
-		revents &= epi->event.events;
-
-		/*
-		 * Is the event mask intersect the caller-requested one,
-		 * deliver the event to userspace. Again, we are holding
-		 * "mtx", so no operations coming from userspace can change
-		 * the item.
-		 */
-		if (revents) {
-			if (__put_user(revents,
-				       &events[eventcnt].events) ||
-			    __put_user(epi->event.data,
-				       &events[eventcnt].data))
-				goto errxit;
-			if (epi->event.events & EPOLLONESHOT)
-				epi->event.events &= EP_PRIVATE_BITS;
-			eventcnt++;
-		}
-		/*
-		 * At this point, noone can insert into ep->rdllist besides
-		 * us. The epoll_ctl() callers are locked out by us holding
-		 * "mtx" and the poll callback will queue them in ep->ovflist.
-		 */
-		if (!(epi->event.events & EPOLLET) &&
-		    (revents & epi->event.events))
-			list_add_tail(&epi->rdllink, &ep->rdllist);
-	}
-	error = 0;
-
-errxit:
-
-	spin_lock_irqsave(&ep->lock, flags);
-	/*
-	 * During the time we spent in the loop above, some other events
-	 * might have been queued by the poll callback. We re-insert them
-	 * inside the main ready-list here.
-	 */
-	for (nepi = ep->ovflist; (epi = nepi) != NULL;
-	     nepi = epi->next, epi->next = EP_UNACTIVE_PTR) {
-		/*
-		 * If the above loop quit with errors, the epoll item might still
-		 * be linked to "txlist", and the list_splice() done below will
-		 * take care of those cases.
-		 */
-		if (!ep_is_linked(&epi->rdllink))
-			list_add_tail(&epi->rdllink, &ep->rdllist);
-	}
-	/*
-	 * We need to set back ep->ovflist to EP_UNACTIVE_PTR, so that after
-	 * releasing the lock, events will be queued in the normal way inside
-	 * ep->rdllist.
-	 */
-	ep->ovflist = EP_UNACTIVE_PTR;
-
-	/*
-	 * In case of error in the event-send loop, or in case the number of
-	 * ready events exceeds the userspace limit, we need to splice the
-	 * "txlist" back inside ep->rdllist.
-	 */
-	list_splice(&txlist, &ep->rdllist);
-
-	if (!list_empty(&ep->rdllist)) {
-		/*
-		 * Wake up (if active) both the eventpoll wait list and the ->poll()
-		 * wait list (delayed after we release the lock).
-		 */
-		if (waitqueue_active(&ep->wq))
-			wake_up_locked(&ep->wq);
-		if (waitqueue_active(&ep->poll_wait))
-			pwake++;
-	}
-	spin_unlock_irqrestore(&ep->lock, flags);
-
-	mutex_unlock(&ep->mtx);
-
-	/* We have to call this outside the lock */
-	if (pwake)
-		ep_poll_safewake(&psw, &ep->poll_wait);
-
-	return eventcnt == 0 ? error: eventcnt;
+	struct ep_send_events_data esed;
+
+	esed.maxevents = maxevents;
+	esed.events = events;
+
+	return ep_scan_ready_list(ep, ep_send_events_proc, &esed);
 }

 static int ep_poll(struct eventpoll *ep, struct epoll_event __user *events,
@@ -1033,7 +1129,7 @@
 	wait_queue_t wait;

 	/*
-	 * Calculate the timeout by checking for the "infinite" value ( -1 )
+	 * Calculate the timeout by checking for the "infinite" value (-1)
 	 * and the overflow condition. The passed timeout is in milliseconds,
 	 * that why (t * HZ) / 1000.
 	 */
@@ -1076,9 +1172,8 @@

 		set_current_state(TASK_RUNNING);
 	}
-
 	/* Is it worth to try to dig for events ? */
-	eavail = !list_empty(&ep->rdllist);
+	eavail = !list_empty(&ep->rdllist) || ep->ovflist != EP_UNACTIVE_PTR;

 	spin_unlock_irqrestore(&ep->lock, flags);

@@ -1099,41 +1194,40 @@
  */
 SYSCALL_DEFINE1(epoll_create1, int, flags)
 {
-	int error, fd = -1;
-	struct eventpoll *ep;
+	int error;
+	struct eventpoll *ep = NULL;

 	/* Check the EPOLL_* constant for consistency.  */
 	BUILD_BUG_ON(EPOLL_CLOEXEC != O_CLOEXEC);

-	if (flags & ~EPOLL_CLOEXEC)
-		return -EINVAL;
-
 	DNPRINTK(3, (KERN_INFO "[%p] eventpoll: sys_epoll_create(%d)\n",
 		     current, flags));

-	/*
-	 * Create the internal data structure ( "struct eventpoll" ).
+	error = -EINVAL;
+	if (flags & ~EPOLL_CLOEXEC)
+		goto error_return;
+
+	/*
+	 * Create the internal data structure ("struct eventpoll").
 	 */
 	error = ep_alloc(&ep);
-	if (error < 0) {
-		fd = error;
+	if (error < 0)
 		goto error_return;
-	}

 	/*
 	 * Creates all the items needed to setup an eventpoll file. That is,
 	 * a file structure and a free file descriptor.
 	 */
-	fd = anon_inode_getfd("[eventpoll]", &eventpoll_fops, ep,
-			      flags & O_CLOEXEC);
-	if (fd < 0)
+	error = anon_inode_getfd("[eventpoll]", &eventpoll_fops, ep,
+				 flags & O_CLOEXEC);
+	if (error < 0)
 		ep_free(ep);

 error_return:
 	DNPRINTK(3, (KERN_INFO "[%p] eventpoll: sys_epoll_create(%d) = %d\n",
-		     current, flags, fd));
-
-	return fd;
+		     current, flags, error));
+
+	return error;
 }

 SYSCALL_DEFINE1(epoll_create, int, size)
@@ -1359,7 +1453,10 @@
 		EP_ITEM_COST;

 	/* Initialize the structure used to perform safe poll wait head wake ups */
-	ep_poll_safewake_init(&psw);
+	ep_nested_calls_init(&poll_safewake_ncalls);
+
+	/* Initialize the structure used to perform file's f_op->poll() calls */
+	ep_nested_calls_init(&poll_readywalk_ncalls);

 	/* Allocates slab cache used to allocate "struct epitem" items */
 	epi_cache = kmem_cache_create("eventpoll_epi", sizeof(struct epitem),


Allow Utility::pow<>() to operate on non-Real values too.

git-svn-id: e88a1e38e13faf406e05cc89eca8dd613216f6c4@4896 434f946d-2f3d-0410-ba4c-cb9f52fb0dbf

--- trunk/libmesh/include/utils/utility.h
+++ trunk/libmesh/include/utils/utility.h
@@ -141,70 +141,52 @@
    * An efficient template instantiation for raising
    * to an arbitrary integer power.
    */
-  template <int N>
+  template <int N, typename T>
+  struct do_pow {
+    static inline T apply (const T& x)
+      {
+        libmesh_assert(N>1);
+
+        if (N%2) // odd exponent
+          return x * do_pow<N-1,T>::apply(x);
+
+        const T xNover2 = do_pow<N/2,T>::apply(x);
+
+        return xNover2*xNover2;
+      }
+  };
+
+  // An efficient compiler would distill N=6 down to 3
+  // multiplications, but an inefficient one (or a complicated
+  // T::operator*) might do worse, so we'll specialize here.
+  template <typename T>
+  struct do_pow<6,T> {
+    static inline T apply (const T& x)
+      {
+        const T x2 = x*x,
+                x4 = x2*x2;
+
+        return x4*x2;
+      }
+  };
+
+  template <typename T>
+  struct do_pow<1,T> {
+    static inline T apply (const T& x) { return x; }
+  };
+
+  template <typename T>
+  struct do_pow<0,T> {
+    static inline T apply (const T&) { return 1; }
+  };
+
+
+  template <int N, typename T>
   inline
-  Real pow(const Real x)
+  T pow(const T& x)
   {
-    libmesh_assert(N>1);
-
-    if (N%2) // odd exponent
-      return x * pow<N-1>(x);
-
-    const Real xNover2 = pow<N/2>(x);
-
-    return xNover2*xNover2;
-  }
-
-  template <>
-  inline
-  Real pow<8>(const Real x)
-  {
-    const Real
-      x2 = x*x,
-      x4 = x2*x2,
-      x8 = x4*x4;
-
-    return x8;
-  }
-
-  template <>
-  inline
-  Real pow<6>(const Real x)
-  {
-    const Real
-      x2 = x*x,
-      x4 = x2*x2,
-      x6 = x4*x2;
-
-    return x6;
-  }
-
-  template <>
-  inline
-  Real pow<4>(const Real x)
-  {
-    const Real
-      x2 = x*x,
-      x4 = x2*x2;
-    return x4;
-  }
-
-  template <>
-  inline
-  Real pow<3>(const Real x) { return x*x*x; }
-
-  template <>
-  inline
-  Real pow<2>(const Real x) { return x*x; }
-
-  template <>
-  inline
-  Real pow<1>(const Real x) { return x; }
-
-  template <>
-  inline
-  Real pow<0>(const Real) { return 1.; }
-
+    return do_pow<N,T>::apply(x);
+  }

   //-------------------------------------------------------------------
   /**


Don't call UNEXPECTED_ERROR if setsockopt(SO_TIMESTAMP) returns ENOPROTOOPT.

--- lib/isc/unix/socket.c
+++ lib/isc/unix/socket.c
@@ -15,7 +15,7 @@
  * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */

-/* $Id: socket.c,v 1.169 2000/10/07 00:16:50 bwelling Exp $ */
+/* $Id: socket.c,v 1.170 2000/10/12 00:35:49 bwelling Exp $ */

 #include <config.h>

@@ -1262,7 +1262,8 @@

 #if defined(SO_TIMESTAMP)
 		if (setsockopt(sock->fd, SOL_SOCKET, SO_TIMESTAMP,
-			       (void *)&on, sizeof on) < 0) {
+			       (void *)&on, sizeof on) < 0
+		    && errno != ENOPROTOOPT) {
 			UNEXPECTED_ERROR(__FILE__, __LINE__,
 					 "setsockopt(%d, SO_TIMESTAMP) "
 					 "failed: %s",


_err() -> err().

_err() -> err().

--- lib/libc/gen/stringlist.c
+++ lib/libc/gen/stringlist.c
@@ -51,13 +51,13 @@
 {
 	StringList *sl = malloc(sizeof(StringList));
 	if (sl == NULL)
-		_err(1, "stringlist: %m");
+		err(1, "stringlist: %m");

 	sl->sl_cur = 0;
 	sl->sl_max = _SL_CHUNKSIZE;
 	sl->sl_str = malloc(sl->sl_max * sizeof(char *));
 	if (sl->sl_str == NULL)
-		_err(1, "stringlist: %m");
+		err(1, "stringlist: %m");
 	return sl;
 }

@@ -74,7 +74,7 @@
 		sl->sl_max += _SL_CHUNKSIZE;
 		sl->sl_str = realloc(sl->sl_str, sl->sl_max * sizeof(char *));
 		if (sl->sl_str == NULL)
-			_err(1, "stringlist: %m");
+			err(1, "stringlist: %m");
 	}
 	sl->sl_str[sl->sl_cur++] = name;
 }


Fix seek bug for 24 bit PAF files.

Fix seek bug for 24 bit PAF files.

--- src/paf.c
+++ src/paf.c
@@ -349,7 +349,7 @@
 static int
 paf24_init (SF_PRIVATE *psf)
 {	PAF24_PRIVATE	*ppaf24 ;
-	int	paf24size, max_blocks ;
+	int	paf24size ;

 	paf24size = sizeof (PAF24_PRIVATE) + psf->sf.channels *
 					(PAF24_BLOCK_SIZE + PAF24_SAMPLES_PER_BLOCK * sizeof (int)) ;
@@ -398,18 +398,18 @@
 	if (psf->datalength % PAF24_BLOCK_SIZE)
 	{	if (psf->mode == SFM_READ)
 			psf_log_printf (psf, "*** Warning : file seems to be truncated.\n") ;
-		max_blocks = psf->datalength / ppaf24->blocksize + 1 ;
+		ppaf24->max_blocks = psf->datalength / ppaf24->blocksize + 1 ;
 		}
 	else
-		max_blocks = psf->datalength / ppaf24->blocksize ;
+		ppaf24->max_blocks = psf->datalength / ppaf24->blocksize ;

 	ppaf24->read_block = 0 ;
 	if (psf->mode == SFM_RDWR)
-		ppaf24->write_block = max_blocks ;
+		ppaf24->write_block = ppaf24->max_blocks ;
 	else
 		ppaf24->write_block = 0 ;

-	psf->sf.frames = ppaf24->samplesperblock * max_blocks ;
+	psf->sf.frames = ppaf24->samplesperblock * ppaf24->max_blocks ;
 	ppaf24->sample_count = psf->sf.frames ;

 	return 0 ;
@@ -435,11 +435,6 @@

 	switch (mode)
 	{	case SFM_READ :
-				if (offset > ppaf24->read_block * ppaf24->samplesperblock + ppaf24->read_count)
-				{	psf->error = SFE_BAD_SEEK ;
-					return SF_SEEK_ERROR ;
-					} ;
-
 				if (psf->last_op == SFM_WRITE && ppaf24->write_count)
 					paf24_write_block (psf, ppaf24) ;


loader: gl167 - Remove unknown inst extensions

Change-Id: I24aecbdab452a04514fd42a9a9ae7f3bcf1cd2ca

--- loader/loader.c
+++ loader/loader.c
@@ -164,6 +164,34 @@
         terminator_GetPhysicalDeviceGeneratedCommandsPropertiesNVX,
 };

+// A null-terminated list of all of the instance extensions supported by the
+// loader
+static const char *const LOADER_INSTANCE_EXTENSIONS[] = {
+    VK_KHR_SURFACE_EXTENSION_NAME,
+    VK_KHR_DISPLAY_EXTENSION_NAME,
+#ifdef VK_USE_PLATFORM_XLIB_KHR
+    VK_KHR_XLIB_SURFACE_EXTENSION_NAME,
+#endif
+#ifdef VK_USE_PLATFORM_XCB_KHR
+    VK_KHR_XCB_SURFACE_EXTENSION_NAME,
+#endif
+#ifdef VK_USE_PLATFORM_WAYLAND_KHR
+    VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME,
+#endif
+#ifdef VK_USE_PLATFORM_MIR_KHR
+    VK_KHR_MIR_SURFACE_EXTENSION_NAME,
+#endif
+#ifdef VK_USE_PLATFORM_ANDROID_KHR
+    VK_KHR_ANDROID_SURFACE_EXTENSION_NAME,
+#endif
+#ifdef VK_USE_PLATFORM_WIN32_KHR
+    VK_KHR_WIN32_SURFACE_EXTENSION_NAME,
+#endif
+    VK_EXT_DEBUG_REPORT_EXTENSION_NAME,
+    VK_NV_EXTERNAL_MEMORY_CAPABILITIES_EXTENSION_NAME,
+    VK_EXT_VALIDATION_FLAGS_EXTENSION_NAME,
+    NULL};
+
 LOADER_PLATFORM_THREAD_ONCE_DECLARATION(once_init);

 void *loader_instance_heap_alloc(const struct loader_instance *instance,
@@ -1237,6 +1265,30 @@
                       .EnumerateInstanceExtensionProperties,
             icd_tramp_list->scanned_list[i].lib_name, &icd_exts);
         if (VK_SUCCESS == res) {
+            // Remove any extensions not recognized by the loader
+            for (int32_t j = 0; j < (int32_t)icd_exts.count; j++) {
+
+                // See if the extension is in the list of supported extensions
+                bool found = false;
+                for (uint32_t k = 0; LOADER_INSTANCE_EXTENSIONS[k] != NULL;
+                     k++) {
+                    if (strcmp(icd_exts.list[j].extensionName,
+                               LOADER_INSTANCE_EXTENSIONS[k]) == 0) {
+                        found = true;
+                        break;
+                    }
+                }
+
+                // If it isn't in the list, remove it
+                if (!found) {
+                    for (uint32_t k = j + 1; k < icd_exts.count; k++) {
+                        icd_exts.list[k - 1] = icd_exts.list[k];
+                    }
+                    --icd_exts.count;
+                    --j;
+                }
+            }
+
             res = loader_add_to_ext_list(inst, inst_exts, icd_exts.count,
                                          icd_exts.list);
         }
@@ -4040,6 +4092,21 @@
             return VK_ERROR_EXTENSION_NOT_PRESENT;
         }

+        // See if the extension is in the list of supported extensions
+        bool found = false;
+        for (uint32_t j = 0; LOADER_INSTANCE_EXTENSIONS[j] != NULL; j++) {
+            if (strcmp(pCreateInfo->ppEnabledExtensionNames[i],
+                       LOADER_INSTANCE_EXTENSIONS[j]) == 0) {
+                found = true;
+                break;
+            }
+        }
+
+        // If it isn't in the list, return an error
+        if (!found) {
+            return VK_ERROR_EXTENSION_NOT_PRESENT;
+        }
+
         extension_prop = get_extension_property(
             pCreateInfo->ppEnabledExtensionNames[i], icd_exts);


Revert incorrect conversion applied to shader code

--- src/chrono_irrlicht/ChIrrEffects.h
+++ src/chrono_irrlicht/ChIrrEffects.h
@@ -494,12 +494,12 @@
     "void main() "
     "{"
     "	vec4 vInfo = gl_TexCoord[0];\n"
-    "	float depth = vInfo.z() / vInfo.x();\n"
+    "	float depth = vInfo.z / vInfo.x;\n"
     "   gl_FragColor = vec4(depth, depth * depth, 0.0, 0.0);\n"
     "}",
     "float4 pixelMain(float4 ClipPos: TEXCOORD0) : COLOR0"
     "{"
-    "	float depth = ClipPos.z() / ClipPos.x();\n"
+    "	float depth = ClipPos.z / ClipPos.x;\n"
     "	return float4(depth, depth * depth, 0.0, 0.0);\n"
     "}"};

@@ -510,7 +510,7 @@
     "{"
     "	vec4 vInfo = gl_TexCoord[0];\n"
     ""
-    "	float depth = vInfo.z() / vInfo.x();\n"
+    "	float depth = vInfo.z / vInfo.x;\n"
     ""
     "	float alpha = texture2D(ColorMapSampler, gl_TexCoord[1].xy).a;\n"
     ""
@@ -520,7 +520,7 @@
     ""
     "float4 pixelMain(float4 Color: TEXCOORD0, float2 Texcoords: TEXCOORD1) : COLOR0"
     "{"
-    "	float depth = Color.z() / Color.w;\n"
+    "	float depth = Color.z / Color.w;\n"
     "	"
     "	float alpha = tex2D(ColorMapSampler, Texcoords).a;\n"
     "	"
@@ -535,7 +535,7 @@
     "{"
     "	vec4 tPos = mWorldViewProj * gl_Vertex;\n"
     "	gl_Position = tPos;\n"
-    "	gl_TexCoord[0] = vec4(MaxD, tPos.y(), tPos.z(), tPos.w);\n"
+    "	gl_TexCoord[0] = vec4(MaxD, tPos.y, tPos.z, tPos.w);\n"
     ""
     "	gl_TexCoord[1].xy = gl_MultiTexCoord0.xy;\n"
     "}",
@@ -553,9 +553,9 @@
     "VS_OUTPUT vertexMain(float3 Position : POSITION0, float2 Texcoords : TEXCOORD0, float4 vColor : COLOR0)"
     "{"
     "	VS_OUTPUT  OUT;\n"
-    "	float4 hpos = mul(float4(Position.x(), Position.y(), Position.z(), 1.0), mWorldViewProj);\n"
+    "	float4 hpos = mul(float4(Position.x, Position.y, Position.z, 1.0), mWorldViewProj);\n"
     "   OUT.ClipPos = hpos;\n"
-    "	OUT.ClipPos.x() = MaxD;\n"
+    "	OUT.ClipPos.x = MaxD;\n"
     "   OUT.Position = hpos;\n"
     "	OUT.Texcoords = Texcoords;\n"
     "	OUT.VColor = vColor;\n"
@@ -572,12 +572,12 @@
     "{\n"
     "	vec4 shadTexCol = texture2D(ShadowMapSampler, texCoords + offset);\n"
     ""
-    "	float lit_factor = (RealDist <= shadTexCol.x()) ? 1.0 : 0.0;\n"
-    ""
-    "	float E_x2 = shadTexCol.y();\n"
-    "	float Ex_2 = shadTexCol.x() * shadTexCol.x();\n"
+    "	float lit_factor = (RealDist <= shadTexCol.x) ? 1.0 : 0.0;\n"
+    ""
+    "	float E_x2 = shadTexCol.y;\n"
+    "	float Ex_2 = shadTexCol.x * shadTexCol.x;\n"
     "	float variance = min(max(E_x2 - Ex_2, 0.00001) + 0.000001, 1.0);\n"
-    "	float m_d = (shadTexCol.x() - RealDist);\n"
+    "	float m_d = (shadTexCol.x - RealDist);\n"
     "	float p = variance / (variance + m_d * m_d);\n"
     ""
     "	return (1.0 - max(lit_factor, p)) / float(SAMPLE_AMOUNT);\n"
@@ -623,23 +623,23 @@
     "	// If this point is within the light's frustum.\n"
     "##ifdef ROUND_SPOTLIGHTS\n"
     "	float lengthToCenter = length(SMPos.xy - vec2(0.5, 0.5));\n"
-    "	if(SMPos.z() - 0.01 > 0.0 && SMPos.z() + 0.01 < MVar.z())\n"
+    "	if(SMPos.z - 0.01 > 0.0 && SMPos.z + 0.01 < MVar.z)\n"
     "##else\n"
     "	vec2 clampedSMPos = clamp(SMPos.xy, vec2(0.0, 0.0), vec2(1.0, 1.0));\n"
-    "	if(clampedSMPos.x() == SMPos.x() && clampedSMPos.y() == SMPos.y() && SMPos.z() > 0.0 && SMPos.z() < MVar.z())\n"
+    "	if(clampedSMPos.x == SMPos.x && clampedSMPos.y == SMPos.y && SMPos.z > 0.0 && SMPos.z < MVar.z)\n"
     "##endif\n"
     "	{"
     "		float lightFactor = 1.0;\n"
-    "		float realDist = MVar.x() / MVar.z() - 0.002;\n"
+    "		float realDist = MVar.x / MVar.z - 0.002;\n"
     "	"
     "		for(int i = 0;i < SAMPLE_AMOUNT; i++)"
     "			lightFactor -= testShadow(SMPos.xy, offsetArray[i] * MVar.w, realDist);\n"
     ""
     "		// Multiply with diffuse.\n"
     "##ifdef ROUND_SPOTLIGHTS\n"
-    "		finalCol = LightColour * lightFactor * MVar.y() * clamp(5.0 - 10.0 * lengthToCenter, 0.0, 1.0);\n"
+    "		finalCol = LightColour * lightFactor * MVar.y * clamp(5.0 - 10.0 * lengthToCenter, 0.0, 1.0);\n"
     "##else\n"
-    "		finalCol = LightColour * lightFactor * MVar.y();\n"
+    "		finalCol = LightColour * lightFactor * MVar.y;\n"
     "##endif\n"
     "	}"
     ""
@@ -654,12 +654,12 @@
     "{"
     "	float4 shadTexCol = tex2D(ShadowMapSampler, texCoords + offset);\n"
     ""
-    "	float lit_factor = (RealDist <= shadTexCol.x());\n"
-    ""
-    "	float E_x2 = shadTexCol.y();\n"
-    "	float Ex_2 = shadTexCol.x() * shadTexCol.x();\n"
+    "	float lit_factor = (RealDist <= shadTexCol.x);\n"
+    ""
+    "	float E_x2 = shadTexCol.y;\n"
+    "	float Ex_2 = shadTexCol.x * shadTexCol.x;\n"
     "	float variance = min(max(E_x2 - Ex_2, 0.00001) + 0.000001, 1.0);\n"
-    "	float m_d = (shadTexCol.x() - RealDist);\n"
+    "	float m_d = (shadTexCol.x - RealDist);\n"
     "	float p = variance / (variance + m_d * m_d);\n"
     "	  "
     "	return (1.0 - max(lit_factor, p)) / SAMPLE_AMOUNT;\n"
@@ -708,10 +708,10 @@
     "	// If this point is within the light's frustum.\n"
     "##ifdef ROUND_SPOTLIGHTS\n"
     "	float lengthToCenter = length(SMPos.xy - float2(0.5, 0.5));\n"
-    "	if(lengthToCenter < 0.5 && SMPos.z() > 0.0 && SMPos.z() < MVar[3])\n"
+    "	if(lengthToCenter < 0.5 && SMPos.z > 0.0 && SMPos.z < MVar[3])\n"
     "##else\n"
     "	float2 clampedSMPos = saturate(SMPos.xy);\n"
-    "	if(clampedSMPos.x() == SMPos.x() && clampedSMPos.y() == SMPos.y() && SMPos.z() > 0.0 && SMPos.z() < MVar[3])\n"
+    "	if(clampedSMPos.x == SMPos.x && clampedSMPos.y == SMPos.y && SMPos.z > 0.0 && SMPos.z < MVar[3])\n"
     "##endif\n"
     "	{"
     "		float lightFactor = 1.0;\n"
@@ -752,14 +752,14 @@
     "{"
     "	VS_OUTPUT OUT;\n"
     ""
-    "	OUT.Position = (mWorldViewProj * vec4(Position.x(), Position.y(), Position.z(), 1.0));\n"
-    "	OUT.ShadowMapSamplingPos = (mWorldViewProj2 * vec4(Position.x(), Position.y(), Position.z(), 1.0));\n"
+    "	OUT.Position = (mWorldViewProj * vec4(Position.x, Position.y, Position.z, 1.0));\n"
+    "	OUT.ShadowMapSamplingPos = (mWorldViewProj2 * vec4(Position.x, Position.y, Position.z, 1.0));\n"
     ""
     "	vec3 lightDir = normalize(LightPos - Position);\n"
     "	"
-    "	OUT.MVar.x() = OUT.ShadowMapSamplingPos.z();\n"
-    "	OUT.MVar.y() = dot(normalize(gl_Normal.xyz), lightDir);\n"
-    "	OUT.MVar.z() = MaxD;\n"
+    "	OUT.MVar.x = OUT.ShadowMapSamplingPos.z;\n"
+    "	OUT.MVar.y = dot(normalize(gl_Normal.xyz), lightDir);\n"
+    "	OUT.MVar.z = MaxD;\n"
     "	OUT.MVar.w = 1.0 / MAPRES;\n"
     ""
     "	return OUT;\n"
@@ -797,15 +797,15 @@
     "  )"
     "{"
     "	VS_OUTPUT  OUT;\n"
-    "    OUT.Position = mul(float4(Position.x(),Position.y(),Position.z(),1.0), mWorldViewProj);\n"
-    "	float4 SMPos = mul(float4(Position.x(),Position.y(),Position.z(),1.0), mWorldViewProj2);\n"
-    "	SMPos.xy = float2(SMPos.x(), -SMPos.y()) / 2.0;\n"
+    "    OUT.Position = mul(float4(Position.x,Position.y,Position.z,1.0), mWorldViewProj);\n"
+    "	float4 SMPos = mul(float4(Position.x,Position.y,Position.z,1.0), mWorldViewProj2);\n"
+    "	SMPos.xy = float2(SMPos.x, -SMPos.y) / 2.0;\n"
     "	"
     "	OUT.ShadowMapSamplingPos = SMPos;\n"
     "		"
     "	float3 LightDir = normalize(LightPos - Position.xyz);\n"
     "	"
-    "	OUT.MVar = float4(SMPos.z(), dot(Normal, LightDir), 1.0 / MAPRES, MaxD);\n"
+    "	OUT.MVar = float4(SMPos.z, dot(Normal, LightDir), 1.0 / MAPRES, MaxD);\n"
     "	OUT.TexCoords = TexCoords;\n"
     "	"
     "	return(OUT);\n"
@@ -879,18 +879,18 @@
     "uniform vec3 LineEnds0, LineEnds1, LineEnds2, LineEnds3; \n"
     "void main() \n"
     "{\n"
-    "	gl_Position = vec4(gl_Vertex.x(), gl_Vertex.y(), 0.0, 1.0); \n"
+    "	gl_Position = vec4(gl_Vertex.x, gl_Vertex.y, 0.0, 1.0); \n"
     "	vec2 tCoords; \n"
-    "	tCoords.x() = 0.5 * (1.0 + gl_Vertex.x()); \n"
-    "	tCoords.y() = 0.5 * (1.0 + gl_Vertex.y()); \n"
+    "	tCoords.x = 0.5 * (1.0 + gl_Vertex.x); \n"
+    "	tCoords.y = 0.5 * (1.0 + gl_Vertex.y); \n"
     "	gl_TexCoord[0].xy = tCoords.xy; \n"
-    "	tCoords.y() = 1.0 - tCoords.y(); \n"
-    "	vec3 tLStart = mix(LineStarts0, LineStarts1, tCoords.x()); \n"
-    "	vec3 bLStart = mix(LineStarts2, LineStarts3, tCoords.x()); \n"
-    "	gl_TexCoord[1].xyz = mix(tLStart, bLStart, tCoords.y()); \n"
-    "	vec3 tLEnd = mix(LineEnds0, LineEnds1, tCoords.x()); \n"
-    "	vec3 bLEnd = mix(LineEnds2, LineEnds3, tCoords.x()); \n"
-    "	gl_TexCoord[2].xyz = mix(tLEnd, bLEnd, tCoords.y()); \n"
+    "	tCoords.y = 1.0 - tCoords.y; \n"
+    "	vec3 tLStart = mix(LineStarts0, LineStarts1, tCoords.x); \n"
+    "	vec3 bLStart = mix(LineStarts2, LineStarts3, tCoords.x); \n"
+    "	gl_TexCoord[1].xyz = mix(tLStart, bLStart, tCoords.y); \n"
+    "	vec3 tLEnd = mix(LineEnds0, LineEnds1, tCoords.x); \n"
+    "	vec3 bLEnd = mix(LineEnds2, LineEnds3, tCoords.x); \n"
+    "	gl_TexCoord[2].xyz = mix(tLEnd, bLEnd, tCoords.y); \n"
     "	gl_TexCoord[3].xy = vec2(screenX, screenY); \n"
     "}",
     "float screenX, screenY; \n"
@@ -907,15 +907,15 @@
     "VS_OUTPUT vertexMain(float3 Position : POSITION0) \n"
     "{ \n"
     "	VS_OUTPUT OUT; \n"
-    "   OUT.Position = float4(Position.x(),Position.y(), 0.0, 1.0); \n"
-    "	OUT.TexCoords.x() = 0.5 * (1.0 + Position.x() + (1.0 / screenX)); \n"
-    "	OUT.TexCoords.y() = 1.0 - 0.5 * (1.0 + Position.y() - (1.0 / screenY)); \n"
-    "	float3 tLStart = lerp(LineStarts0, LineStarts1, OUT.TexCoords.x()); \n"
-    "	float3 bLStart = lerp(LineStarts2, LineStarts3, OUT.TexCoords.x()); \n"
-    "	OUT.LStart = lerp(tLStart, bLStart, OUT.TexCoords.y()); \n"
-    "	float3 tLEnd = lerp(LineEnds0, LineEnds1, OUT.TexCoords.x()); \n"
-    "	float3 bLEnd = lerp(LineEnds2, LineEnds3, OUT.TexCoords.x()); \n"
-    "	OUT.LEnd = lerp(tLEnd, bLEnd, OUT.TexCoords.y()); \n"
+    "   OUT.Position = float4(Position.x,Position.y, 0.0, 1.0); \n"
+    "	OUT.TexCoords.x = 0.5 * (1.0 + Position.x + (1.0 / screenX)); \n"
+    "	OUT.TexCoords.y = 1.0 - 0.5 * (1.0 + Position.y - (1.0 / screenY)); \n"
+    "	float3 tLStart = lerp(LineStarts0, LineStarts1, OUT.TexCoords.x); \n"
+    "	float3 bLStart = lerp(LineStarts2, LineStarts3, OUT.TexCoords.x); \n"
+    "	OUT.LStart = lerp(tLStart, bLStart, OUT.TexCoords.y); \n"
+    "	float3 tLEnd = lerp(LineEnds0, LineEnds1, OUT.TexCoords.x); \n"
+    "	float3 bLEnd = lerp(LineEnds2, LineEnds3, OUT.TexCoords.x); \n"
+    "	OUT.LEnd = lerp(tLEnd, bLEnd, OUT.TexCoords.y); \n"
     "	OUT.ScreenSize = float2(screenX, screenY); \n"
     "	return(OUT); \n"
     "} \n"};
@@ -930,16 +930,16 @@
     "\n"
     "##ifdef VERTICAL_VSM_BLUR\n"
     "	offsetArray[0] = vec2(0.0, 0.0);\n"
-    "	offsetArray[1] = vec2(0.0, -1.5 / gl_TexCoord[3].y());\n"
-    "	offsetArray[2] = vec2(0.0, 1.5 / gl_TexCoord[3].y());\n"
-    "	offsetArray[3] = vec2(0.0, -2.5 / gl_TexCoord[3].y());\n"
-    "	offsetArray[4] = vec2(0.0, 2.5 / gl_TexCoord[3].y());\n"
+    "	offsetArray[1] = vec2(0.0, -1.5 / gl_TexCoord[3].y);\n"
+    "	offsetArray[2] = vec2(0.0, 1.5 / gl_TexCoord[3].y);\n"
+    "	offsetArray[3] = vec2(0.0, -2.5 / gl_TexCoord[3].y);\n"
+    "	offsetArray[4] = vec2(0.0, 2.5 / gl_TexCoord[3].y);\n"
     "##else\n"
     "	offsetArray[0] = vec2(0.0, 0.0);\n"
-    "	offsetArray[1] = vec2(-1.5 / gl_TexCoord[3].x(), 0.0);\n"
-    "	offsetArray[2] = vec2(1.5 / gl_TexCoord[3].x(), 0.0);\n"
-    "	offsetArray[3] = vec2(-2.5 / gl_TexCoord[3].x(), 0.0);\n"
-    "	offsetArray[4] = vec2(2.5 / gl_TexCoord[3].x(), 0.0);\n"
+    "	offsetArray[1] = vec2(-1.5 / gl_TexCoord[3].x, 0.0);\n"
+    "	offsetArray[2] = vec2(1.5 / gl_TexCoord[3].x, 0.0);\n"
+    "	offsetArray[3] = vec2(-2.5 / gl_TexCoord[3].x, 0.0);\n"
+    "	offsetArray[4] = vec2(2.5 / gl_TexCoord[3].x, 0.0);\n"
     "##endif\n"
     "\n"
     "	vec4 BlurCol = vec4(0.0, 0.0, 0.0, 0.0);\n"
@@ -957,16 +957,16 @@
     "	float2 offsetArray[5];\n"
     "##ifdef VERTICAL_VSM_BLUR\n"
     "	offsetArray[0] = float2(0, 0);\n"
-    "	offsetArray[1] = float2(0, 1.5 / ScreenSize.y());\n"
-    "	offsetArray[2] = float2(0, -1.5 / ScreenSize.y());\n"
-    "	offsetArray[3] = float2(0, 2.5 / ScreenSize.y());\n"
-    "	offsetArray[4] = float2(0, -2.5 / ScreenSize.y());\n"
+    "	offsetArray[1] = float2(0, 1.5 / ScreenSize.y);\n"
+    "	offsetArray[2] = float2(0, -1.5 / ScreenSize.y);\n"
+    "	offsetArray[3] = float2(0, 2.5 / ScreenSize.y);\n"
+    "	offsetArray[4] = float2(0, -2.5 / ScreenSize.y);\n"
     "##else\n"
     "	offsetArray[0] = float2(0, 0);\n"
-    "	offsetArray[1] = float2(1.5 / ScreenSize.x(), 0);\n"
-    "	offsetArray[2] = float2(-1.5 / ScreenSize.x(), 0);\n"
-    "	offsetArray[3] = float2(2.5 / ScreenSize.x(), 0);\n"
-    "	offsetArray[4] = float2(-2.5 / ScreenSize.x(), 0);\n"
+    "	offsetArray[1] = float2(1.5 / ScreenSize.x, 0);\n"
+    "	offsetArray[2] = float2(-1.5 / ScreenSize.x, 0);\n"
+    "	offsetArray[3] = float2(2.5 / ScreenSize.x, 0);\n"
+    "	offsetArray[4] = float2(-2.5 / ScreenSize.x, 0);\n"
     "##endif\n"
     "\n"
     "	float4 finalVal = float4(0.0, 0.0, 0.0, 0.0);\n"


gchecksum: Fix validity checks for GChecksumType

This fixes the unit tests after commit 3e32350b rearranged the enum
order.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

https://bugzilla.gnome.org/show_bug.cgi?id=771997

--- glib/gchecksum.c
+++ glib/gchecksum.c
@@ -52,7 +52,7 @@
  * Support for checksums has been added in GLib 2.16
  **/

-#define IS_VALID_TYPE(type)     ((type) >= G_CHECKSUM_MD5 && (type) <= G_CHECKSUM_SHA512)
+#define IS_VALID_TYPE(type)     ((type) >= G_CHECKSUM_MD5 && (type) <= G_CHECKSUM_SHA384)

 /* The fact that these are lower case characters is part of the ABI */
 static const gchar hex_digits[] = "0123456789abcdef";


f2fs: avoid f2fs_balance_fs call during pageout

This patch should resolve the following bug.

=========================================================
[ INFO: possible irq lock inversion dependency detected ]
3.13.0-rc5.f2fs+ #6 Not tainted
---------------------------------------------------------
kswapd0/41 just changed the state of lock:
 (&sbi->gc_mutex){+.+.-.}, at: [<ffffffffa030503e>] f2fs_balance_fs+0xae/0xd0 [f2fs]
but this lock took another, RECLAIM_FS-READ-unsafe lock in the past:
 (&sbi->cp_rwsem){++++.?}

and interrupts could create inverse lock ordering between them.

other info that might help us debug this:
Chain exists of:
  &sbi->gc_mutex --> &sbi->cp_mutex --> &sbi->cp_rwsem

 Possible interrupt unsafe locking scenario:

       CPU0                    CPU1
       ----                    ----
  lock(&sbi->cp_rwsem);
                               local_irq_disable();
                               lock(&sbi->gc_mutex);
                               lock(&sbi->cp_mutex);
  <Interrupt>
    lock(&sbi->gc_mutex);

 *** DEADLOCK ***

This bug is due to the f2fs_balance_fs call in f2fs_write_data_page.
If f2fs_write_data_page is triggered by wbc->for_reclaim via kswapd, it should
not call f2fs_balance_fs which tries to get a mutex grabbed by original syscall
flow.

Signed-off-by: Jaegeuk Kim <20424effba9d4aeeb410130c5f23aa328fa29e09@samsung.com>


MFC	r268569:
strfmon: reduce unnecessary snprintf.

No need for the snprintf/asprintf dance; use fixed width formats.

Obtained from:	NetBSD (CVS rev. 1.8)


Got rid of some unnecessary font setting.

--- src/pdf.c
+++ src/pdf.c
@@ -204,8 +204,8 @@
 		state->y = HPDF_Page_GetHeight(state->page) - MARGIN_TOP;
 		state->x = MARGIN_LEFT + state->indent;
 		state->last_text_y = state->y;
-	}
-	HPDF_Page_SetFontAndSize (state->page, state->main_font, state->current_font_size);
+		HPDF_Page_SetFontAndSize (state->page, state->main_font, state->current_font_size);
+	}
 	return STATUS_OK;
 }

@@ -467,7 +467,6 @@
 			return STATUS_ERR;
 		}
 		process_boxes(state, false);
-		HPDF_Page_SetFontAndSize (state->page, state->main_font, state->current_font_size);
 		state->y -= (state->current_font_size + state->leading);
 		return STATUS_OK;

@@ -475,17 +474,11 @@
 		if (entering) {
 			int lev = cmark_node_get_header_level(node);
 			state->current_font_size = state->base_font_size * (1.66 - (lev/6));
-			HPDF_Page_SetFontAndSize (state->page,
-						  state->main_font,
-						  state->current_font_size);
 			parbreak(state);
 		} else {
 			process_boxes(state, true);
 			state->y -= (0.3 * (state->current_font_size + state->leading));
 			state->current_font_size = state->base_font_size;
-			HPDF_Page_SetFontAndSize (state->page,
-						  state->main_font,
-						  state->current_font_size);
 		}
 		break;


gmessages: make _g_log_abort() do only breakpoints again

Commit e53caad4 makes _g_log_abort() noreturn by calling abort()
unconditionally.

However, it is useful to be able to skip some log_abort() with a
debugger, to reach a point of interest. Revert back to previous
behaviour. Make g_assert_warning() noreturn by calling abort().

https://bugzilla.gnome.org/show_bug.cgi?id=711800

--- glib/gmessages.c
+++ glib/gmessages.c
@@ -290,7 +290,7 @@

 /* --- functions --- */

-static void _g_log_abort (gboolean breakpoint) G_GNUC_NORETURN;
+static void _g_log_abort (gboolean breakpoint);

 static void
 _g_log_abort (gboolean breakpoint)
@@ -307,8 +307,8 @@

   if (breakpoint)
     G_BREAKPOINT ();
-
-  abort ();
+  else
+    abort ();
 }

 #ifdef G_OS_WIN32
@@ -1130,6 +1130,7 @@
 	 pretty_function,
 	 expression);
   _g_log_abort (FALSE);
+  abort ();
 }

 /**


f2fs: reuse nids more aggressively

f2fs: reuse nids more aggressively

If we can reuse nids as many as possible, we can mitigate producing obsolete
node pages in the page cache.

Reviewed-by: Chao Yu <0cc5db7488e13b393f245aa6263acec5e92fdcc5@samsung.com>
Signed-off-by: Jaegeuk Kim <71255387a32c360dfbe6dfb7aaeb123bf1dc8cb6@kernel.org>


copy/paste error

copy/paste error

--- src/pdo.c
+++ src/pdo.c
@@ -133,7 +133,7 @@
 	     if (objDict != OD_SUCCESSFUL) {
 	        MSG_WAR(0x2919, "error accessing to the mapped var : ", subInd + 1);
 		MSG_WAR(0x2920, "         Mapped at index : ", (*pMappingParameter) >> 16);
-		MSG_WAR(0x2921, "                subindex : "getODentry, ((*pMappingParameter) >> 8 ) & 0xFF);
+		MSG_WAR(0x2921, "                subindex : ", ((*pMappingParameter) >> 8 ) & 0xFF);
 		return 0xFF;
 	     }


fuse: prevent fuse_put_request on invalid pointer

fuse_direct_io() has a loop where requests are allocated in each
iteration. if allocation fails, the loop is broken out and follows
into an unconditional fuse_put_request() on that invalid pointer.

Signed-off-by: Anand V. Avati <6a1810c170bd423868ce2e225ecea39d80cade0f@gluster.com>
Signed-off-by: Miklos Szeredi <84cd5483a2f9acd1c37251cba7c2908448f221b8@suse.cz>
Cc: 4fbacc2fa0ffdbb11bf1ad6925b886ebd08dd15f@kernel.org

--- fs/fuse/file.c
+++ fs/fuse/file.c
@@ -1063,7 +1063,8 @@
 				break;
 		}
 	}
-	fuse_put_request(fc, req);
+	if (!IS_ERR(req))
+		fuse_put_request(fc, req);
 	if (res > 0)
 		*ppos = pos;


Colour lookup: Return false if given colour index is invalid.

--- src/pen.c
+++ src/pen.c
@@ -33,18 +33,21 @@
   0x85, 0x90, 0x9B, 0xA6, 0xB1, 0xBC, 0xC7, 0xD2, 0xDD, 0xE8, 0xF3, 0xFF,
 };

-static void lookup_colour_ansi(const VTermState *state, long index, VTermColor *col)
+static bool lookup_colour_ansi(const VTermState *state, long index, VTermColor *col)
 {
   if(index >= 0 && index < 16) {
     *col = state->colors[index];
-  }
-}
-
-static void lookup_colour_palette(const VTermState *state, long index, VTermColor *col)
+    return true;
+  }
+
+  return false;
+}
+
+static bool lookup_colour_palette(const VTermState *state, long index, VTermColor *col)
 {
   if(index >= 0 && index < 16) {
     // Normal 8 colours or high intensity - parse as palette 0
-    lookup_colour_ansi(state, index, col);
+    return lookup_colour_ansi(state, index, col);
   }
   else if(index >= 16 && index < 232) {
     // 216-colour cube
@@ -53,15 +56,21 @@
     col->blue  = ramp6[index     % 6];
     col->green = ramp6[index/6   % 6];
     col->red   = ramp6[index/6/6 % 6];
+
+    return true;
   }
   else if(index >= 232 && index < 256) {
     // 24 greyscales
     index -= 232;

+    col->blue  = ramp24[index];
+    col->green = ramp24[index];
     col->red   = ramp24[index];
-    col->green = ramp24[index];
-    col->blue  = ramp24[index];
-  }
+
+    return true;
+  }
+
+  return false;
 }

 static int lookup_colour(const VTermState *state, int palette, const long args[], int argcount, VTermColor *col, int *index)


gfs2: allow fallocate to max out quotas/fs efficiently

We can quickly get an estimate of how many blocks are available
for allocation restricted by quota and fs size respectively, using
the ap->allowed field in the gfs2_alloc_parms structure.
gfs2_quota_check() and gfs2_inplace_reserve() provide these values.

Once we have the total number of blocks available to us, we can
compute how many bytes of data can be written using those blocks
instead of guessing inefficiently.

Signed-off-by: Abhi Das <0d65ec5fc381668782b153e0078f3ea20344faa3@redhat.com>
Signed-off-by: Bob Peterson <0c71a8c45d1c28c49aceef3749b4faa9d3c35c54@redhat.com>
Acked-by: Steven Whitehouse <9801c4ef11586b619a1c43ac9377eea2aee672dd@redhat.com>


Don't leak a FD on error

Don't leak a FD on error

--- src/pty.c
+++ src/pty.c
@@ -1203,6 +1203,8 @@
                 close(tmp[1]);
         if (tunnel != -1)
                 close(tunnel);
+        if (_vte_pty_helper_tunnel != -1)
+                close(_vte_pty_helper_tunnel);

         _vte_pty_helper_pid = -1;
         _vte_pty_helper_tunnel = -1;


hfs: avoid crash in hfs_bnode_create

hfs: avoid crash in hfs_bnode_create

Commit 634725a92938 ("hfs: cleanup HFS+ prints") removed the BUG_ON in
hfs_bnode_create in hfsplus.  This patch removes it from the hfs version
and avoids an fsfuzzer crash.

Signed-off-by: Jeff Mahoney <5459ed423adecc5a7fe2249dd619058acc25c497@suse.com>
Acked-by: Jeff Mahoney <5459ed423adecc5a7fe2249dd619058acc25c497@suse.com>
Signed-off-by: Jiri Slaby <dfbf39eb5bf303a3db5454d815cb8c8888cbadf9@suse.cz>
Cc: Vyacheslav Dubeyko <ab6b0d3a9a5b93cc5a527a2be8b0aca4398fecb5@dubeyko.com>
Signed-off-by: Andrew Morton <5c1e68b099950c134891f0b6e179498a8ebe9cf9@linux-foundation.org>
Signed-off-by: Linus Torvalds <69652caca27c8b940640ad396ab71f93cacec34f@linux-foundation.org>

--- fs/hfs/bnode.c
+++ fs/hfs/bnode.c
@@ -415,7 +415,11 @@
 	spin_lock(&tree->hash_lock);
 	node = hfs_bnode_findhash(tree, num);
 	spin_unlock(&tree->hash_lock);
-	BUG_ON(node);
+	if (node) {
+		pr_crit("new node %u already hashed?\n", num);
+		WARN_ON(1);
+		return node;
+	}
 	node = __hfs_bnode_create(tree, num);
 	if (!node)
 		return ERR_PTR(-ENOMEM);


Setting TERM environment variable to "xterm-256color"

--- src/pty.c
+++ src/pty.c
@@ -193,6 +193,9 @@
   int result;
   struct winsize ws;
   struct termios attr;
+  /* Set TERM environment variable to xterm-256color, since libtsm approximates
+   * the functionality of xterm */
+  setenv("TERM", "xterm-256color", 1);
   /* Allow the child to access the pseudo terminal */
   if (grantpt(self->master_fd) < 0) {
     perror("grantpt");


NFS4: Set security flavor default for NFSv4 mounts like other defaults

Set the default security flavor when we set the other mount option
default values for NFSv4.  This cleans up the NFSv4 mount option parsing
path to look like the NFSv2/v3 one.

Signed-off-by: Chuck Lever <e7d8216bf9b1956703857d0050bd04192118f43d@oracle.com>
Signed-off-by: Trond Myklebust <6a1f9db795c9fc44be97d66ab114c53193bd3d13@netapp.com>

--- fs/nfs/super.c
+++ fs/nfs/super.c
@@ -2125,6 +2125,8 @@
 	args->acdirmin		= NFS_DEF_ACDIRMIN;
 	args->acdirmax		= NFS_DEF_ACDIRMAX;
 	args->nfs_server.port	= NFS_PORT; /* 2049 unless user set port= */
+	args->auth_flavors[0]	= RPC_AUTH_UNIX;
+	args->auth_flavor_len	= 0;

 	switch (data->version) {
 	case 1:
@@ -2140,18 +2142,13 @@
 						&args->nfs_server.address))
 			goto out_no_address;

-		switch (data->auth_flavourlen) {
-		case 0:
-			args->auth_flavors[0] = RPC_AUTH_UNIX;
-			break;
-		case 1:
+		if (data->auth_flavourlen) {
+			if (data->auth_flavourlen > 1)
+				goto out_inval_auth;
 			if (copy_from_user(&args->auth_flavors[0],
 					   data->auth_flavours,
 					   sizeof(args->auth_flavors[0])))
 				return -EFAULT;
-			break;
-		default:
-			goto out_inval_auth;
 		}

 		c = strndup_user(data->hostname.data, NFS4_MAXNAMLEN);
@@ -2203,15 +2200,8 @@

 		nfs_validate_transport_protocol(args);

-		switch (args->auth_flavor_len) {
-		case 0:
-			args->auth_flavors[0] = RPC_AUTH_UNIX;
-			break;
-		case 1:
-			break;
-		default:
+		if (args->auth_flavor_len > 1)
 			goto out_inval_auth;
-		}

 		if (args->client_address == NULL)
 			goto out_no_client_address;


raf->pending only for librt

raf->pending only for librt

--- src/raf.c
+++ src/raf.c
@@ -177,8 +177,8 @@
 #ifdef HAVE_LIBRT
 	raf->request.aio_fildes=fd;
 	raf->request.aio_reqprio=0;
+	raf->pending=0;
 #endif
-	raf->pending=0;
 	return raf;
 }


small app to spit out some stats about disk cache

error: pathspec 'priv/cache_inspector.c' did not match any file(s) known to git

--- priv/cache_inspector.c
+++ priv/cache_inspector.c
@@ -0,0 +1,45 @@
+
+//==============================================================================
+//
+// Compile:
+// $ gcc -Wall -o cache_inspector cache_inspector.c
+//
+// Usage:
+// $ ./cache_inspector < molderl.cache
+//
+// Requirements:
+// * work on unix systems
+//
+//==============================================================================
+
+#include<stdio.h>
+#include <unistd.h>
+
+int main() {
+
+    ssize_t nbytes;
+    unsigned char buf[2];
+    unsigned int packet_length;
+    unsigned int packet_counter = 0;
+    unsigned int minimum = 20000; // ~2x bigger than jumbo frames MTU, to be safe
+    unsigned int maximum = 0;
+    unsigned int total_size = 0;
+
+    do { // loop over MoldUDP64 packets
+        nbytes = read(STDIN_FILENO, buf, 2);
+        packet_length = ((int)buf[0] << 8) | buf[1];
+        total_size += packet_length;
+        minimum = packet_length < minimum ? packet_length : minimum;
+        maximum = packet_length > maximum ? packet_length : maximum;
+        ++packet_counter;
+        lseek(STDIN_FILENO, packet_length, SEEK_CUR);
+    } while (nbytes != 0);
+
+    printf("number of packets: %u\n", packet_counter);
+    printf("total data (bytes): %u\n", total_size);
+    printf("smallest packet (bytes): %u\n", minimum);
+    printf("avg packet size (bytes): %u\n", total_size/packet_counter);
+    printf("largest packet (bytes): %u\n", maximum);
+    return 0;
+}
+


NFS: Eliminate duplicate call to nfs_mark_request_dirty

We only need to call nfs_mark_request_dirty() once in nfs_writepage_setup().

Signed-off-by: Trond Myklebust <6a1f9db795c9fc44be97d66ab114c53193bd3d13@netapp.com>

--- fs/nfs/write.c
+++ fs/nfs/write.c
@@ -680,7 +680,6 @@
 	req = nfs_setup_write_request(ctx, page, offset, count);
 	if (IS_ERR(req))
 		return PTR_ERR(req);
-	nfs_mark_request_dirty(req);
 	/* Update file length */
 	nfs_grow_file(page, offset, count);
 	nfs_mark_uptodate(page, req->wb_pgbase, req->wb_bytes);


Remove slave state change handled by replicationSetupSlaveForFullResync().

--- src/rdb.c
+++ src/rdb.c
@@ -1571,7 +1571,6 @@
         if (slave->replstate == SLAVE_STATE_WAIT_BGSAVE_START) {
             clientids[numfds] = slave->id;
             fds[numfds++] = slave->fd;
-            slave->replstate = SLAVE_STATE_WAIT_BGSAVE_END;
             replicationSetupSlaveForFullResync(slave,getPsyncInitialOffset());
             /* Put the socket in non-blocking mode to simplify RDB transfer.
              * We'll restore it when the children returns (since duped socket