begin separating EXE load vs CLSG entry point detection.

--- objexp/x1/test.c
+++ objexp/x1/test.c
@@ -21,19 +21,6 @@

 static inline unsigned long exe_resident_len(const struct exeload_ctx * const exe) {
     return (unsigned long)exe->len_seg << 4UL;
-}
-
-static inline unsigned short exe_func_count(const struct exeload_ctx * const exe) {
-    return *((unsigned short*)MK_FP(exe->base_seg,4));
-}
-
-static inline unsigned short exe_func_ento(const struct exeload_ctx * const exe,const unsigned int i) {
-    return *((unsigned short*)MK_FP(exe->base_seg,4+2+(i*2U)));
-}
-
-/* NTS: You're supposed to typecast return value into function pointer prototype */
-static inline void far *exe_func_ent(const struct exeload_ctx * const exe,const unsigned int i) {
-    return (void far*)MK_FP(exe->base_seg,exe_func_ento(exe,i));
 }

 int load_exe(struct exeload_ctx *exe,const char * const path) {
@@ -166,28 +153,6 @@
                 *((unsigned short far*)MK_FP(exe->base_seg+s,o)) += exe->base_seg;
             }
         }
-    }
-
-    /* final check: CLSG at the beginning of the resident image and a valid function call table */
-    {
-        unsigned char far *p = MK_FP(exe->base_seg,0);
-        unsigned short far *functbl = (unsigned short far*)(p+4UL+2UL);
-        unsigned short numfunc;
-        unsigned int i;
-
-        if (*((unsigned long far*)(p+0)) != 0x47534C43UL) goto fail; // seg:0 = CLSG
-
-        numfunc = *((unsigned short far*)(p+4UL));
-        if (((numfunc*2UL)+4UL+2UL) > (img_sz+add_sz-hdr_sz)) goto fail;
-
-        /* none of the functions can point outside the EXE resident image. */
-        for (i=0;i < numfunc;i++) {
-            unsigned short fo = functbl[i];
-            if ((unsigned long)fo >= (img_sz+add_sz-hdr_sz)) goto fail;
-        }
-
-        /* the last entry after function table must be 0xFFFF */
-        if (functbl[numfunc] != 0xFFFFU) goto fail;
     }

     if (hdr != NULL) free(hdr);
@@ -208,11 +173,54 @@
     exe->len_seg = 0;
 }

+int exe_clsg_validate_header(const struct exeload_ctx * const exe) {
+    /* CLSG at the beginning of the resident image and a valid function call table */
+    unsigned char far *p = MK_FP(exe->base_seg,0);
+    unsigned short far *functbl = (unsigned short far*)(p+4UL+2UL);
+    unsigned long exe_len = exe_resident_len(exe);
+    unsigned short numfunc;
+    unsigned int i;
+
+    if (*((unsigned long far*)(p+0)) != 0x47534C43UL) return 0; // seg:0 = CLSG
+
+    numfunc = *((unsigned short far*)(p+4UL));
+    if (((numfunc*2UL)+4UL+2UL) > exe_len) return 0;
+
+    /* none of the functions can point outside the EXE resident image. */
+    for (i=0;i < numfunc;i++) {
+        unsigned short fo = functbl[i];
+        if ((unsigned long)fo >= exe_len) return 0;
+    }
+
+    /* the last entry after function table must be 0xFFFF */
+    if (functbl[numfunc] != 0xFFFFU) return 0;
+
+    return 1;
+}
+
+static inline unsigned short exe_func_count(const struct exeload_ctx * const exe) {
+    return *((unsigned short*)MK_FP(exe->base_seg,4));
+}
+
+static inline unsigned short exe_func_ento(const struct exeload_ctx * const exe,const unsigned int i) {
+    return *((unsigned short*)MK_FP(exe->base_seg,4+2+(i*2U)));
+}
+
+/* NTS: You're supposed to typecast return value into function pointer prototype */
+static inline void far *exe_func_ent(const struct exeload_ctx * const exe,const unsigned int i) {
+    return (void far*)MK_FP(exe->base_seg,exe_func_ento(exe,i));
+}
+
 int main() {
     if (!load_exe(&final_exe,"final.exe")) {
         fprintf(stderr,"Load failed\n");
         return 1;
     }
+    if (!exe_clsg_validate_header(&final_exe)) {
+        fprintf(stderr,"EXE is not valid CLSG\n");
+        free_exe(&final_exe);
+        return 1;
+    }

     fprintf(stderr,"EXE image loaded to %04x:0000 residentlen=%lu\n",final_exe.base_seg,(unsigned long)final_exe.len_seg << 4UL);
     {


Clara is not amused by 5-person groups

Clara is not amused by 5-person groups

--- Clara/alint.c
+++ Clara/alint.c
@@ -26,6 +26,8 @@
  */
 ALInt * ali_init() {
   // STUB
+  // What is this even supposed to do
+  return NULL;
 }

 /**
@@ -50,6 +52,7 @@
  */
 void ali_cleanup() {
   // STUB
+  // Wait how am I supposed to find allocated ALInts to free them
 }


Semicolon.

Semicolon.

--- C/modern.h
+++ C/modern.h
@@ -368,7 +368,7 @@
   (modern_autorelease_pool *pool,
    size_t *length);
 extern uint8_t *modern_output_stream_memory_allocating_result
-  (void *stream_state, size_t *length)
+  (void *stream_state, size_t *length);
 extern void *modern_output_stream_file
   (modern_autorelease_pool *pool,
    FILE *file);


Fixed one bug in UefiPxeBc start()/stop(). That would cause stop() failure.

git-svn-id: 5648d1bec6962b0a6d1d1b40eba8cf5cdb62da3d@4553 6f19259b-4bc3-4df7-8a09-765794883524

--- MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcDriver.c
+++ MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcDriver.c
@@ -1,6 +1,6 @@
 /** @file

-Copyright (c) 2007, Intel Corporation
+Copyright (c) 2007 - 2008, Intel Corporation
 All rights reserved. This program and the accompanying materials
 are licensed and made available under the terms and conditions of the BSD License
 which accompanies this distribution.  The full text of the license may be found at
@@ -285,7 +285,7 @@
     NetLibDestroyServiceChild (
       ControllerHandle,
       This->DriverBindingHandle,
-      &gEfiUdp4ProtocolGuid,
+      &gEfiUdp4ServiceBindingProtocolGuid,
       Private->Udp4Child
       );
   }
@@ -301,7 +301,7 @@
     NetLibDestroyServiceChild (
       ControllerHandle,
       This->DriverBindingHandle,
-      &gEfiMtftp4ProtocolGuid,
+      &gEfiMtftp4ServiceBindingProtocolGuid,
       Private->Mtftp4Child
       );
   }
@@ -317,7 +317,7 @@
     NetLibDestroyServiceChild (
       ControllerHandle,
       This->DriverBindingHandle,
-      &gEfiDhcp4ProtocolGuid,
+      &gEfiDhcp4ServiceBindingProtocolGuid,
       Private->Dhcp4Child
       );
   }
@@ -398,10 +398,10 @@
           Private->Udp4Child,
           &gEfiUdp4ProtocolGuid,
           This->DriverBindingHandle,
-          ControllerHandle
-          );
-    NetLibDestroyServiceChild (
-      ControllerHandle,
+          NicHandle
+          );
+    NetLibDestroyServiceChild (
+      NicHandle,
       This->DriverBindingHandle,
       &gEfiUdp4ServiceBindingProtocolGuid,
       Private->Udp4Child
@@ -411,10 +411,10 @@
           Private->Dhcp4Child,
           &gEfiDhcp4ProtocolGuid,
           This->DriverBindingHandle,
-          ControllerHandle
-          );
-    NetLibDestroyServiceChild (
-      ControllerHandle,
+          NicHandle
+          );
+    NetLibDestroyServiceChild (
+      NicHandle,
       This->DriverBindingHandle,
       &gEfiDhcp4ServiceBindingProtocolGuid,
       Private->Dhcp4Child
@@ -424,10 +424,10 @@
           Private->Mtftp4Child,
           &gEfiMtftp4ProtocolGuid,
           This->DriverBindingHandle,
-          ControllerHandle
-          );
-    NetLibDestroyServiceChild (
-      ControllerHandle,
+          NicHandle
+          );
+    NetLibDestroyServiceChild (
+      NicHandle,
       This->DriverBindingHandle,
       &gEfiMtftp4ServiceBindingProtocolGuid,
       Private->Mtftp4Child


presync: removing exit() calls on create(); using error handling api

--- src/framing/src/presync.c
+++ src/framing/src/presync.c
@@ -68,13 +68,10 @@
                            unsigned int _m)
 {
     // validate input
-    if (_n < 1) {
-        fprintf(stderr, "error: bpresync_%s_create(), invalid input length\n", EXTENSION_FULL);
-        exit(1);
-    } else if (_m == 0) {
-        fprintf(stderr, "error: bpresync_%s_create(), number of correlators must be at least 1\n", EXTENSION_FULL);
-        exit(1);
-    }
+    if (_n < 1)
+        return liquid_error_config("bpresync_%s_create(), invalid input length", EXTENSION_FULL);
+    if (_m == 0)
+        return liquid_error_config("bpresync_%s_create(), number of correlators must be at least 1", EXTENSION_FULL);

     // allocate main object memory and initialize
     PRESYNC() _q = (PRESYNC()) malloc(sizeof(struct PRESYNC(_s)));
@@ -227,10 +224,8 @@
                         float complex * _rxy1)
 {
     // validate input...
-    if (_id >= _q->m) {
-        fprintf(stderr,"error: bpresync_%s_correlatex(), invalid id\n", EXTENSION_FULL);
-        exit(1);
-    }
+    if (_id >= _q->m)
+        return liquid_error(LIQUID_EICONFIG,"bpresync_%s_correlatex(), invalid id", EXTENSION_FULL);

     // get buffer pointers
     T * ri = NULL;


增加连连看难度

增加连连看难度

--- OOP_Term_Project_PVZ/OOP_Term_Project_PVZ/paireliminate.h
+++ OOP_Term_Project_PVZ/OOP_Term_Project_PVZ/paireliminate.h
@@ -6,6 +6,7 @@
 #include <QPainter>
 #include <QMessageBox>
 #include <QSignalMapper>
+#include <QDebug>
 #include <iostream>
 #include <fstream>
 #include <algorithm>
@@ -36,12 +37,12 @@
     static const int TEMPLATE_COUNT = 10;
     static const int CARD_COUNT = 24;

-    static const int MAX_TIME = 60; // 游戏时间
+    static const int MAX_TIME = 50; // 游戏时间
     static const int MAX_TIME_DISPLAY = 1000 / TIME_ELAPSE * MAX_TIME; // 进度条长度
     static const int LINE_TIME = 0.5 * 1000 / TIME_ELAPSE;

-    static const int ELIMINATE_PRIZE = 1 * 1000 / TIME_ELAPSE;
-    static const int HINT_COST = 5 * 1000 / TIME_ELAPSE;
+    static const int ELIMINATE_PRIZE = 0.5 * 1000 / TIME_ELAPSE;
+    static const int HINT_COST = 6 * 1000 / TIME_ELAPSE;
     static constexpr double SHUFFLE_COST = 1.0 / 3;

 private:


fix an issue when syncing spoof metadata between gmond nodes in multicast mode

--- gmond/gmond.c
+++ gmond/gmond.c
@@ -855,6 +855,7 @@
 Ganglia_metadata_check(Ganglia_host *host, Ganglia_value_msg *vmsg )
 {
     char *metric_name = vmsg->Ganglia_value_msg_u.gstr.metric_id.name;
+    int is_spoof_msg = vmsg->Ganglia_value_msg_u.gstr.metric_id.spoof;
     Ganglia_metadata *metric =
         (Ganglia_metadata *)apr_hash_get(host->metrics, metric_name, APR_HASH_KEY_STRING);

@@ -863,12 +864,17 @@
         int len;
         XDR x;
         char msgbuf[GANGLIA_MAX_MESSAGE_LEN];
+        char hostbuf[512];
         Ganglia_metadata_msg msg;

         msg.id = gmetadata_request;
-        msg.Ganglia_metadata_msg_u.grequest.metric_id.host = host->hostname;
+        if (is_spoof_msg)
+            apr_snprintf(hostbuf, 512, "%s:%s", host->ip, host->hostname);
+        else
+            apr_snprintf(hostbuf, 512, "%s", host->hostname);
+        msg.Ganglia_metadata_msg_u.grequest.metric_id.host = hostbuf;
         msg.Ganglia_metadata_msg_u.grequest.metric_id.name = metric_name;
-        msg.Ganglia_metadata_msg_u.grequest.metric_id.spoof = FALSE;
+        msg.Ganglia_metadata_msg_u.grequest.metric_id.spoof = is_spoof_msg;

         debug_msg("sending metadata request flag for metric: %s host: %s", metric_name, host->hostname);
         ganglia_scoreboard_inc(PKTS_SENT_REQUEST);
@@ -987,9 +993,21 @@
 Ganglia_metadata_request( Ganglia_host *host, Ganglia_metadata_msg *message )
 {
   char *name = message->Ganglia_metadata_msg_u.grequest.metric_id.name;
-  Ganglia_metric_callback *metric_cb =  (Ganglia_metric_callback *)
-                apr_hash_get( metric_callbacks, name, APR_HASH_KEY_STRING );
-
+  Ganglia_metric_callback *metric_cb;
+  int is_spoof_msg = message->Ganglia_metadata_msg_u.grequest.metric_id.spoof;
+
+  if(is_spoof_msg)
+    {
+      char *srch_name[512];
+
+      apr_snprintf(srch_name, 512, "%s:%s", name, host->hostname);
+      metric_cb =  (Ganglia_metric_callback *)apr_hash_get( metric_callbacks, srch_name, APR_HASH_KEY_STRING );
+    }
+  else
+    {
+      metric_cb =  (Ganglia_metric_callback *)apr_hash_get( metric_callbacks, name, APR_HASH_KEY_STRING );
+    }
+
   if(!host || !message)
     return;

@@ -1932,26 +1950,34 @@
         /* Replace the host metric name with the spoof data if it exists in the metadata */
         if (metric_info->metadata)
         {
-            const char *val;
+            const char *spfhost_val, *spfname_val;

-            val = apr_table_get((apr_table_t *)metric_info->metadata, SPOOF_HOST);
-            if (val)
+            spfhost_val = apr_table_get((apr_table_t *)metric_info->metadata, SPOOF_HOST);
+            if (spfhost_val)
             {
-                metric_cb->msg.Ganglia_value_msg_u.gstr.metric_id.host = apr_pstrdup(global_context, val);
+                metric_cb->msg.Ganglia_value_msg_u.gstr.metric_id.host = apr_pstrdup(global_context, spfhost_val);
                 metric_cb->msg.Ganglia_value_msg_u.gstr.metric_id.spoof = TRUE;
+                spfhost_val = strchr(spfhost_val,':');
+                if(spfhost_val)
+                    spfhost_val++;
+                else
+                    spfhost_val = metric_cb->msg.Ganglia_value_msg_u.gstr.metric_id.host;
             }
-            val = apr_table_get((apr_table_t *)metric_info->metadata, SPOOF_NAME);
-            if (val)
+            else
+              spfhost_val = myname;
+            spfname_val = apr_table_get((apr_table_t *)metric_info->metadata, SPOOF_NAME);
+            if (spfname_val)
             {
-                char *spoofedname = apr_pstrcat(global_context, val, ":", name, NULL);
-
+                char *spoofedname = apr_pstrcat(global_context, spfname_val, ":", name, NULL);
+                char *spoofedkey = apr_pstrcat(global_context, spfname_val, ":", name, ":", spfhost_val, NULL);
+
                 metric_cb->msg.Ganglia_value_msg_u.gstr.metric_id.name = spoofedname;
                 metric_cb->msg.Ganglia_value_msg_u.gstr.metric_id.spoof = TRUE;

                 /* Reinsert the same metric_callback structure pointer under the spoofed name.
                     This will put the same metric info in the hash table twice but under
                     the spoofed name. */
-                apr_hash_set( metric_callbacks, spoofedname, APR_HASH_KEY_STRING, metric_cb);
+                apr_hash_set( metric_callbacks, spoofedkey, APR_HASH_KEY_STRING, metric_cb);
             }
         }


Don't reset the time comparison variable during the metric send loop.
Use the time value that was set during the main() loop so that the
metric expirations are handled at the same time.

Submitted by: Matthias Blankenhaus <matthias sgi com>
Reviewed by: Brad Nicholes <bnicholes novell com>

git-svn-id: 27e0aca8c7a52a9ae65dfba2e16879604119af8c@931 93a4e39c-3214-0410-bb16-828d8e3bcd0f

--- gmond/gmond.c
+++ gmond/gmond.c
@@ -1769,6 +1769,7 @@
                   if (strcasecmp(name,  mi[k].name) == 0)
                     {
                       memcpy (metric_info, &(mi[k]), sizeof(Ganglia_25metric));
+                      break;
                     }
                 }

@@ -1959,7 +1960,6 @@
         int len, errors;
         char metricmsg[max_udp_message_len];
         Ganglia_metric_callback *cb = ((Ganglia_metric_callback **)(group->metric_array->elts))[i];
-        apr_time_t now = apr_time_now();

         /* Build the message */
         switch(cb->info->type)


fix compiler warnings and AF_INET6 test for Cygwin

--- gmond/sflow.c
+++ gmond/sflow.c
@@ -1030,13 +1030,13 @@
   submit_sflow_double(hostdata, metric_prefix, SFLOW_M_jvm_nhmem_used, (double)jvm_nhmem_used, SFLOW_OK_GAUGE64(jvm_nhmem_used));
   submit_sflow_double(hostdata, metric_prefix, SFLOW_M_jvm_nhmem_committed, (double)jvm_nhmem_committed, SFLOW_OK_GAUGE64(jvm_nhmem_committed));
   submit_sflow_double(hostdata, metric_prefix, SFLOW_M_jvm_nhmem_max, (double)jvm_nhmem_max, SFLOW_OK_GAUGE64(jvm_nhmem_max));
-  submit_sflow_double(hostdata, metric_prefix, SFLOW_M_jvm_cls_loaded, (double)jvm_cls_loaded, SFLOW_OK_GAUGE64(jvm_cls_loaded));
-  submit_sflow_double(hostdata, metric_prefix, SFLOW_M_jvm_cls_total, (double)jvm_cls_total, SFLOW_OK_GAUGE64(jvm_cls_total));
-  submit_sflow_double(hostdata, metric_prefix, SFLOW_M_jvm_cls_unloaded, (double)jvm_cls_unloaded, SFLOW_OK_GAUGE64(jvm_cls_unloaded));
-  submit_sflow_double(hostdata, metric_prefix, SFLOW_M_jvm_thread_live, (double)jvm_thread_live, SFLOW_OK_GAUGE64(jvm_thread_live));
-  submit_sflow_double(hostdata, metric_prefix, SFLOW_M_jvm_thread_daemon, (double)jvm_thread_daemon, SFLOW_OK_GAUGE64(jvm_thread_daemon));
-  submit_sflow_double(hostdata, metric_prefix, SFLOW_M_jvm_fds_open, (double)jvm_fds_open, SFLOW_OK_GAUGE64(jvm_fds_open));
-  submit_sflow_double(hostdata, metric_prefix, SFLOW_M_jvm_fds_max, (double)jvm_fds_max, SFLOW_OK_GAUGE64(jvm_fds_max));
+  submit_sflow_double(hostdata, metric_prefix, SFLOW_M_jvm_cls_loaded, (double)jvm_cls_loaded, SFLOW_OK_GAUGE32(jvm_cls_loaded));
+  submit_sflow_double(hostdata, metric_prefix, SFLOW_M_jvm_cls_total, (double)jvm_cls_total, SFLOW_OK_GAUGE32(jvm_cls_total));
+  submit_sflow_double(hostdata, metric_prefix, SFLOW_M_jvm_cls_unloaded, (double)jvm_cls_unloaded, SFLOW_OK_GAUGE32(jvm_cls_unloaded));
+  submit_sflow_double(hostdata, metric_prefix, SFLOW_M_jvm_thread_live, (double)jvm_thread_live, SFLOW_OK_GAUGE32(jvm_thread_live));
+  submit_sflow_double(hostdata, metric_prefix, SFLOW_M_jvm_thread_daemon, (double)jvm_thread_daemon, SFLOW_OK_GAUGE32(jvm_thread_daemon));
+  submit_sflow_double(hostdata, metric_prefix, SFLOW_M_jvm_fds_open, (double)jvm_fds_open, SFLOW_OK_GAUGE32(jvm_fds_open));
+  submit_sflow_double(hostdata, metric_prefix, SFLOW_M_jvm_fds_max, (double)jvm_fds_max, SFLOW_OK_GAUGE32(jvm_fds_max));
 }

@@ -1166,7 +1166,7 @@
      * as a metric prefix if required.  (I think there may be an apr call to
      * do this in one go?)
      */
-    snprintf(mprefix, SFLOW_MAX_METRIC_PREFIX_LEN, "%u", dataSource->dsIndex);
+    snprintf(mprefix, SFLOW_MAX_METRIC_PREFIX_LEN, "%u", (unsigned int)dataSource->dsIndex);
     mprefix_len = strlen(mprefix);
     dataSource->metric_prefix = apr_pcalloc(hostdata->pool, mprefix_len);
     memcpy(dataSource->metric_prefix, mprefix, mprefix_len);
@@ -1345,10 +1345,26 @@
   }

   /* turn the agent ip into a string */
-  if(my_inet_ntop(x->agentAddr.type == SFLOW_ADDRTYPE_IP6 ? AF_INET6 : AF_INET,
-		  &x->agentAddr.a,
-		  x->agentipstr,
-		  SFLOW_MAX_HOSTNAME_LEN) == NULL) {
+  if(x->agentAddr.type == SFLOW_ADDRTYPE_IP6) {
+#if defined(HAVE_INET_NTOP) && defined(AF_INET6)
+    my_inet_ntop(AF_INET6, &x->agentAddr.a, x->agentipstr, SFLOW_MAX_HOSTNAME_LEN);
+#else
+    /* Probably on Cygwin, or some other platform that does not support IPv6.
+     just print it out myself - all we need is a unique string so don't worry
+     about compact formatting. */
+    snprintf(x->agentipstr, SFLOW_MAX_HOSTNAME_LEN, "%04x:%04x:%04x:%04x",
+	     x->agentAddr.a.ip6[0],
+	     x->agentAddr.a.ip6[1],
+	     x->agentAddr.a.ip6[2],
+	     x->agentAddr.a.ip6[3]);
+#endif
+  }
+  else {
+    my_inet_ntop(AF_INET, &x->agentAddr.a, x->agentipstr, SFLOW_MAX_HOSTNAME_LEN);
+  }
+
+  /* make sure we got something sensible */
+  if(x->agentipstr == NULL || x->agentipstr[0] == '\0') {
     *errorMsg =  "sFlow agent address format error";
     return FALSE;
   }


version 1.999.117rc2

version 1.999.117rc2

--- misc/version.h
+++ misc/version.h
@@ -35,7 +35,7 @@
 #define BADVPN_MISC_VERSION_H

 #define GLOBAL_PRODUCT_NAME "BadVPN"
-#define GLOBAL_VERSION "1.999.117rc1"
+#define GLOBAL_VERSION "1.999.117rc2"
 #define GLOBAL_COPYRIGHT_NOTICE "Copyright (C) 2010 Ambroz Bizjak <ambrop7@gmail.com>"

 #endif


version 1.999.94

version 1.999.94

git-svn-id: e4cff62102d161c5f2a02ad4c00fc75df921e9eb@23 1a93d707-3861-5ebc-ad3b-9740d49b5140

--- misc/version.h
+++ misc/version.h
@@ -28,7 +28,7 @@
 #define BADVPN_MISC_VERSION_H

 #define GLOBAL_PRODUCT_NAME "BadVPN"
-#define GLOBAL_VERSION "1.999.93.1"
+#define GLOBAL_VERSION "1.999.94"
 #define GLOBAL_COPYRIGHT_NOTICE "Copyright (C) 2010 Ambroz Bizjak <ambrop7@gmail.com>"

 #endif


version 1.999.116rc1

version 1.999.116rc1

--- misc/version.h
+++ misc/version.h
@@ -28,7 +28,7 @@
 #define BADVPN_MISC_VERSION_H

 #define GLOBAL_PRODUCT_NAME "BadVPN"
-#define GLOBAL_VERSION "1.999.115"
+#define GLOBAL_VERSION "1.999.116rc1"
 #define GLOBAL_COPYRIGHT_NOTICE "Copyright (C) 2010 Ambroz Bizjak <ambrop7@gmail.com>"

 #endif


Delete RJMCMC.h

Delete RJMCMC.h

--- Code/RJMCMC.h
+++ Code/RJMCMC.h
@@ -1,921 +0,0 @@
-#ifndef RJMCMC_H
-#define RJMCMC_H
-
-#include <cmath>
-#include <time.h>
-#include <gsl/gsl_randist.h>
-#include <gsl/gsl_rng.h>
-#include "particle.h"
-#include "Data.h"
-#include "string_manipulations.h"
-#include "histogram_type.h"
-#define LOG_TWO log(2.0)
-#define LOG_THREE log(3.0)
-#define ONE_THIRD 1.0/3.0;
-
-using namespace std;
-
-
-template< class T>
-  class rj{
-
- public:
-  rj(double = 0, double =1, long long int = 10, int = 1000, long long int =1, long long int=100, bool=0,Particle<T> * = NULL, int seed = 0, bool = false,bool=false);
-  rj(int argc, char *argv[], Particle<T> * =NULL, int seed = 0, bool = false);
-
-  virtual ~rj();
-
-  virtual void initiate_sample(Particle<T> *);
-  virtual T* generate_new_parameter() const = 0;
-  virtual T* move_parameter(unsigned int) const {return NULL;}
-  virtual double log_likelihood_ratio_birth(T *, int) = 0;
-  virtual double log_likelihood_ratio_death(unsigned int) = 0;
-  virtual double log_likelihood_ratio_move(T *, unsigned int) = 0;
-  virtual double log_prior_ratio_birth() const = 0;
-  virtual double log_prior_ratio_death() const = 0;
-  virtual double log_prior_ratio_move() const = 0;
-  virtual double log_proposal_ratio_birth(T*) const = 0;
-  virtual double log_proposal_ratio_death(int) const = 0;
-  virtual double log_proposal_ratio_move() const = 0;
-  double birth_proposal(unsigned int) const;
-  double death_proposal(unsigned int) const;
-  double move_proposal(unsigned int) const;
-  virtual void update_likelihood_birth(T*,int,double) = 0;
-  virtual void update_likelihood_death(unsigned int, double) = 0;
-  virtual void update_likelihood_move(T*, int, double) = 0;
-  virtual Particle<T> * copy_particle(Particle<T> *);
-  virtual void destroy_sample();
-  virtual void update_log_posterior();
-  virtual Particle<T>** get_sample() const {return m_sample;}
-  virtual Particle<T>* get_current_particle() const {return m_current_particle;}
-  void delete_current_particle(){delete m_current_particle;}
-  virtual double get_end_time() const {return m_end_time;}
-  virtual void set_initial_sample(Particle<T> * initial) {m_initial_sample = initial;}
-  virtual void calculate_function_of_interest() = 0;
-  void open_sample_stream();
-  void print_sample();
-  void open_size_of_sample_stream();
-  void print_size_of_sample();
-  void open_logposterior_of_sample_stream();
-  void print_logposterior_of_sample();
-  void write_frequency_counts_to_file(const char* ="dimension_distribution.txt");
-  void write_1d_histogram_to_file(const string output_filename="1d_distribution.txt"){m_histogram->write_1d_histogram_to_file(output_filename);}
-  void write_marginal_histogram_to_file(const string output_filename="marginal_distribution.txt",unsigned int dimension=1,unsigned int margin=0){m_histogram->write_marginal_histogram_to_file(output_filename,dimension,margin);}
-  void write_primary_function_of_interest_to_file(const string ="foi.txt");
-  map<vector<unsigned int>,long long unsigned int>* get_bin_counts() {if (m_histogram) return m_histogram->get_bin_counts(); return NULL;}
-  Histogram* get_histogram(){return m_histogram;}
-  double get_autocorrelation_prob(){ return m_histogram->get_autocorrelation_prob();}
-  // Particle<T> * get_MAP() const {return m_MAP;};
-  unsigned int get_MAP_dimension() const {return m_MAP_dimension;};
-  Particle<T> * get_MAP(unsigned int k) {return m_MAPs[k];};
-  Particle<T> * get_MAP_dimension_MAP() {return m_MAPs[m_MAP_dimension];};
-  virtual void locally_perfect_MAP(Particle<T>* = NULL, bool = false ) = 0;
-  //virtual int getMAPlength() const = 0;
-  unsigned long long int get_size_sample()const{return m_size_of_sample;}
-  void set_continue_loop(bool loop){m_continue_loop=loop;}
-  void runsimulation();
-  void start_calculating_mc_divergence(Divergence_Type=BIAS,Loss_Function=MINIMAX,unsigned int=50,bool=false,unsigned int=0,bool=false,unsigned int=0);
-  void update_dimension_distribution();
-  virtual void update_histograms();
-  virtual void update_primary_function_of_interest(){;}
-  double get_divergence();
-  void set_mc_divergence_chi_delta(double delta){ mc_divergence::set_delta(delta); }
-  void end_divergence_burn_in(){ m_histogram->set_divergence_initial_number_of_bins();}
-  void set_initial_iterations(long long int ii){m_initial_iterations=ii;}
-  void set_function_criteria(unsigned int);
-  void set_sample_filename(string s){m_sample_filename = s;}
-  void set_sample_dimensions_filename(string s){m_sample_dimensions_filename = s;}
-  void set_sample_logposterior_filename(string s){m_sample_logposterior_filename = s;}
-  void start_printing_sample();
-  void stop_printing_sample();
-  void start_storing_sample(){m_storing_sample=true; if(!m_sample) m_sample = new Particle<T>* [m_iterations];}
-  void stop_storing_sample(){m_storing_sample=false;}
-  void print_current_sample();
-  virtual void print_acceptance_rates();
-  void do_hill_climbing(){m_hill_climbing=true;}
-  void set_discrete(bool d){m_discrete=d;}
-  virtual void update_new_parameter_with_position( T*, unsigned int ) {}
-  void calculate_sample_histogram( bool mv=false, unsigned int num_bins=50, bool bounded=false, bool weighted_histogram=false, bool calculate_divergence=false, Divergence_Type divergence_type=BIAS, Loss_Function loss_fn=MINIMAX, unsigned int look_up_length=0, bool estaimte_cor=false, unsigned int max_dim=0 );
-  void calculate_current_bin();
-  void no_1d_histogram(){ m_calculate_1d_sample_histogram = false; }
-  virtual double get_component_value( T* ){ return 0;}
-  virtual void set_histogram_component_value_function()=0;
-  void do_importance_sampling(){ m_importance_sampling = true; }
-  virtual void calculate_importance_weight(){}
-  double get_sum_thinned_importance_weights(){ return m_sum_thinned_importance_weights; }
-
- protected:
-
-  double m_start_time;
-  double m_end_time;
-  long long int m_iterations;
-  unsigned int m_max_theta;
-  long long int m_thinning;
-  long long int m_burnin;
-  Particle<T> * m_initial_sample;
-  unsigned int m_length_grid;
-
-  bool m_calculate_div;
-  int m_seed;
-  unsigned long long int m_size_of_sample;
-  Particle<T> * m_current_particle;
-  unsigned int m_k;//dimension of m_current_particle
-  double m_log_likelihood_ratio;
-  double m_log_proposal_ratio;
-  double m_log_prior_ratio;
-  double m_log_posterior_ratio;
-  double m_b; //probability of doing a birth
-  double m_d; //probability of doing a death
-  double m_m; //probability of doing a move
-  //  Particle<T> * m_MAP;
-  map<unsigned int,Particle<T> *> m_MAPs;//m_MAPs[k] gives the MAP model of dimension k.
-  map<unsigned int,unsigned long long int> m_dimension_frequency_count;//stores frequency counts for the parameter dimensions visited during MCMC.
-  map<unsigned int,long double> m_dimension_frequency_weight;//a weighted version, for importance sampling
-  unsigned int m_num_bins;
-  bool m_count_dimension_frequencies;//determines whether or not to use dimension_frequency_count and map_dimension;
-  double m_bin_width;
-  Histogram_Type<T> *m_histogram;
-  unsigned int m_MAP_dimension;//the parameter dimension most frequently visited.
-  bool m_calculate_sample_histogram;//determines whether or not to use dimension_frequency_count and map_dimension;
-  bool m_calculate_mv_sample_histogram;//(only if m_calculate_sample_histogram) Determines whether or not to calcluate transdimensional histogram.
-  bool m_calculate_1d_sample_histogram;//(only if m_calculate_sample_histogram) Determines whether or not to calcluate 1d histogram.
-  bool m_calculate_function;
-  //double m_grid_points;
-  //  double *m_function_of_interest;
-  double *m_mean_function_of_interest;
-  double *m_mean_sq_function_of_interest;
-  double *m_var_function_of_interest;
-  double m_mean_var_function_of_interest;
-  bool m_delete_data;
-  void rj_construct();
-  unsigned long long int m_birth_attempt;
-  unsigned long long int m_death_attempt;
-  unsigned long long int m_move_attempt;
-  unsigned long long int m_birth_accept;
-  unsigned long long int m_death_accept;
-  unsigned long long int m_move_accept;
-  bool m_accept;
-  bool m_hill_climbing;//if true, accept iff logposterior increases
-  bool m_calculating_divergence;
-  bool m_use_function_criteria;
-  bool m_importance_sampling;
-  long double m_current_log_importance_weight, m_current_importance_weight;
-  long double m_sum_importance_weights, m_sum_thinned_importance_weights;
-  long long int m_initial_iterations;
-  const gsl_rng_type * r_type;
-  gsl_rng * r;
-
-  bool m_continue_loop;
-  long long int m_iters;
-  Particle<T> ** m_sample;
-  string m_sample_filename;
-  string m_sample_dimensions_filename;
-  string m_sample_logposterior_filename;
-  ofstream m_sample_stream;
-  ofstream m_sample_dimensions_stream;
-  ofstream m_sample_logposterior_stream;
-  bool m_storing_sample;
-  bool m_discrete;
-  double m_start_cps;
-  bool m_printing_sample;
-  bool m_printing_sample_value;//only valid of m_printing_sample == true
-  bool m_printing_sample_dimension;//only valid of m_printing_sample == true
-  bool m_printing_sample_posterior;//only valid of m_printing_sample == true
-
-};
-
-template<class T>
-rj<T>::rj(double begin, double end, long long int its, int max, long long int thin, long long int burnin, bool calcKL,Particle<T> * initial,int se, bool store_sample,bool discrete)
-:m_start_time(begin),m_end_time(end),m_iterations(its),m_max_theta(max),m_thinning(thin),m_burnin(burnin),m_initial_sample(initial),m_calculate_div(calcKL),m_seed(se),m_storing_sample(store_sample),m_discrete(discrete),m_start_cps(begin)
-  {
-    m_start_cps=m_start_time;
-    set_initial_sample(initial);
-    rj_construct();
-  }
-
-
-
-template<class T>
-  rj<T>::~rj()
-{
-  //cout<<"rj destructor called"<<endl;
-
-  if(m_sample!=NULL){
-    destroy_sample();
-    delete [] m_sample;
-  }
-
-  if (m_current_particle){
-    delete m_current_particle;
-  }
-
-  //  if(m_MAP)
-  // delete m_MAP;
-
-  for(typename std::map<unsigned int,Particle<T> *>::iterator iter = m_MAPs.begin(); iter != m_MAPs.end(); ++iter)
-    delete iter->second;
-
-  m_MAPs.erase(m_MAPs.begin(),m_MAPs.end());
-
-
-   gsl_rng_free(r);
-
-  if(m_histogram)
-    delete m_histogram;
-
-  if(m_mean_function_of_interest)
-    delete [] m_mean_function_of_interest;
-  if(m_mean_sq_function_of_interest)
-    delete [] m_mean_sq_function_of_interest;
-  if(m_var_function_of_interest)
-    delete [] m_var_function_of_interest;
-
-  //cout<<"rj destructor called"<<endl;
-}
-
-template<class T>
-  void rj<T>::rj_construct(){
-
-  m_calculating_divergence = false;
-  m_use_function_criteria = false;
-  m_count_dimension_frequencies = true;
-  m_calculate_sample_histogram = false;
-  m_calculate_mv_sample_histogram = false;
-  m_calculate_1d_sample_histogram = true;
-
-  m_continue_loop=0;
-
-  //  if(m_calculate_div)
-  //   m_storing_sample = true;
-  m_sample = m_storing_sample ? new Particle<T>* [m_iterations] : NULL;
-  //  m_sample = new Particle<T>* [m_iterations];
-
-
-  m_current_particle = NULL;
-
-  //  m_MAP = NULL;
-
-  m_MAP_dimension = 0;
-
-  m_histogram = NULL;
-
-
-  m_num_bins = 50;
-  m_bin_width = (m_end_time-m_start_time)/m_num_bins;
-
-  if(m_calculate_div){
-    m_initial_iterations=500;
-  }
-
-  m_mean_function_of_interest=NULL;
-  m_mean_sq_function_of_interest=NULL;
-  m_var_function_of_interest=NULL;
-  m_length_grid=1;
-
-  m_size_of_sample=m_iterations;
-
-  // set_initial_sample(initial);
-
-  //  double seed = time(NULL);
-  //  double seed = 1;
-  int seed=m_seed;
-
-  gsl_rng_env_setup();
-  r_type=gsl_rng_default;
-  r = gsl_rng_alloc(r_type);
-  gsl_rng_set(r,seed);
-  //   srand(seed);
-
-  m_sample_filename = "sampleRJ.txt";
-  m_sample_dimensions_filename = "sizesampleRJ.txt";
-  m_sample_logposterior_filename = "logposterior_sampleRJ.txt";
-  m_printing_sample = false;
-  m_printing_sample_value = !true;
-  m_printing_sample_dimension = true;
-  m_printing_sample_posterior = true;
-  m_hill_climbing = false;
-  m_importance_sampling = false;
-  m_current_log_importance_weight = 0;
-  m_current_importance_weight = 1;
-  m_sum_importance_weights = m_sum_thinned_importance_weights = 0;
-  //cout<<"rj constructor called"<<endl;
-}
-
-template<class T>
-void rj<T>::set_function_criteria(unsigned int grid){
-
-  m_use_function_criteria = true;
-  m_length_grid=grid;
-  m_mean_function_of_interest =  new double [m_length_grid];
-  m_mean_sq_function_of_interest = new double [m_length_grid];
-  m_var_function_of_interest =  new double [m_length_grid];
-  for(unsigned int i=0; i<m_length_grid; i++)
-    m_mean_function_of_interest[i] = m_mean_sq_function_of_interest[i] = m_var_function_of_interest[i] = 0;
-
-}
-
-
-
-template<class T>
-  void  rj<T>::runsimulation()
-{
-
-  bool first=0;
-
-
-  //if this is the first time runsimulation is called initialize variables, allows you to go in an out of the loop used for variable number of particles
-  if(!m_continue_loop){
-    m_birth_attempt = 0;
-    m_death_attempt = 0;
-    m_move_attempt = 0;
-    m_birth_accept = 0;
-    m_death_accept = 0;
-    m_move_accept = 0;
-    m_continue_loop=1;
-
-    initiate_sample(m_initial_sample);
-    m_iters = -m_burnin;
-    first=1;
-
-  }
-  long long int n_iters;
-  // double KLS_old=0;
-
-  double u1,u2;
-  T* new_value=NULL;
-  unsigned int new_position=0;
-  int index_theta_delete=0;
-  int index_theta_move=0;
-  bool gsl_b=0;
-
-    m_k = m_current_particle->get_dim_theta();
-    m_accept = true;
-  //for (long long int i= -m_burnin; i<m_iterations*m_thinning; i++){
-  while(m_continue_loop){
-    n_iters=m_iters/m_thinning;
-
-    if( m_accept ){
-      m_b = birth_proposal(m_k);
-      m_d = death_proposal(m_k);
-      m_m = move_proposal(m_k);
-    }
-    m_log_proposal_ratio = 0;
-
-    u1=gsl_ran_flat(r,0,1);//(double)rand()/(double)RAND_MAX;
-    //birth
-    if(u1<=m_b/* || i==(-m_burnin)*/){
-      //  cout<< "birth" << endl;
-      new_value = generate_new_parameter();
-      new_position = m_current_particle->find_position(new_value);
-      if(new_position<=m_k){
-	update_new_parameter_with_position( new_value, new_position );
-	m_log_likelihood_ratio = log_likelihood_ratio_birth(new_value, new_position);
-	m_log_prior_ratio = log_prior_ratio_birth();
-	if(!m_k)
-	  m_log_proposal_ratio = (m_max_theta == 1) ? -LOG_TWO:-LOG_THREE;
-	else if(m_k == m_max_theta-1)
-	  m_log_proposal_ratio = (m_max_theta == 1) ? -LOG_TWO:LOG_THREE-LOG_TWO;
-	m_log_proposal_ratio += log_proposal_ratio_birth(new_value);
-      }else{
-	m_log_likelihood_ratio=-1;
-	m_log_prior_ratio=-1;
-	m_log_proposal_ratio=-1;
-	gsl_b=1;
-	cerr<<"gsl is shit"<<" "<<*new_value<<" "<<m_iters<<endl;
-      }
-      if(m_iters>0)
-	m_birth_attempt++;
-    }
-    //death
-    else if (u1<=m_b+m_d && u1>m_b){
-      //   cout<< "death"<< endl;
-      index_theta_delete = static_cast<int>( gsl_ran_flat( r, 0, m_k ) );//zarand() % m_k;
-      m_log_likelihood_ratio = log_likelihood_ratio_death(index_theta_delete);
-      m_log_prior_ratio = log_prior_ratio_death();
-      if(m_k == 1)
-	m_log_proposal_ratio = (m_max_theta == 1) ? LOG_TWO:LOG_THREE;
-      else if(m_k == m_max_theta)
-	m_log_proposal_ratio = (m_max_theta == 1) ? LOG_TWO:LOG_TWO-LOG_THREE;
-      m_log_proposal_ratio += log_proposal_ratio_death(index_theta_delete);
-      if(m_iters>0)
-	m_death_attempt++;
-    }
-    //move
-    else {
-      //   cout<< "move"<< endl;
-      index_theta_move = static_cast<unsigned int>( gsl_ran_flat( r, 0, m_k ) );//rand() % m_k;
-      new_value =  move_parameter(index_theta_move);
-      m_log_likelihood_ratio = log_likelihood_ratio_move(new_value, index_theta_move);
-      m_log_prior_ratio = log_prior_ratio_move();
-      m_log_proposal_ratio += log_proposal_ratio_move();
-      if(m_iters>0)
-	m_move_attempt++;
-    }
-
-    m_log_posterior_ratio = m_log_likelihood_ratio + m_log_prior_ratio;
-
-    if(m_iters>0 && m_hill_climbing){
-      m_accept = m_log_posterior_ratio > 0;
-    }
-    else{
-      if (m_log_posterior_ratio + m_log_proposal_ratio >= 0 ){
-	m_accept = 1;
-      }else{
-	if(gsl_b){
-	  u2=0;
-	  gsl_b=0;
-	}else{
-	  u2=log( gsl_ran_flat( r, 0, 1 ) );}
-
-	//log( (double)rand()/(double)RAND_MAX);
-	if (u2<m_log_posterior_ratio + m_log_proposal_ratio){
-	  m_accept = 1;
-	} else{
-	  m_accept = 0;
-	}
-      }
-    }
-
-    if (m_accept) {
-      //birth
-      if (u1<=m_b/* || i==(-m_burnin)*/){
-	update_likelihood_birth(new_value,new_position,m_log_likelihood_ratio);
-	m_current_particle -> add_component(new_value,new_position);
-
-	if(m_iters>0)
-	  m_birth_accept++;
-      }
-      //death
-      else if (u1<=m_b+m_d && u1>m_b){
-	update_likelihood_death(index_theta_delete,m_log_likelihood_ratio);
-	m_current_particle -> delete_component(index_theta_delete);
-
-	if(m_iters>0)
-	  m_death_accept++;
-      }
-      //move
-      else{
-	update_likelihood_move(new_value,index_theta_move,m_log_likelihood_ratio);
-	m_current_particle -> change_component(new_value, index_theta_move);
-
-	if(m_iters>0)
-	  m_move_accept++;
-      }
-
-      m_k = m_current_particle->get_dim_theta();
-
-      update_log_posterior();
-
-      if(m_iters>0 && ((m_iters % m_thinning) == 0)){
-	if(m_storing_sample)
-	  m_sample[n_iters-1]=copy_particle(m_current_particle);
-	else if(m_sample)
-	  m_sample[n_iters-1]=m_current_particle;
-	if(m_printing_sample)
-	  print_current_sample();
-      }
-    }else{
-
-      if(m_iters==m_thinning){
-	if(m_storing_sample){
-	  m_sample[0]= copy_particle(m_current_particle);
-	}
-	else if(m_sample){
-	  m_sample[0]=m_current_particle;
-	}
-	if(m_printing_sample)
-	  print_current_sample();
-      }
-
-      if(m_iters>m_thinning  && ((m_iters % m_thinning) == 0)){
-
-	if(m_sample){
-	  if (m_sample[n_iters -2] == m_current_particle){
-	    m_sample[n_iters-1] = m_sample[n_iters -2];
-	  }
-	  else{
-	    m_sample[n_iters-1]=copy_particle(m_current_particle);
-	  }
-	}
-	if(m_printing_sample)
-	  print_current_sample();
-      }
-
-      if (u1<m_b||u1>m_b+m_d){
-	delete new_value;
-      }
-    }
-
-    /*if(m_iters==-m_burnin){
-
-      m_MAP=copy_particle(m_current_particle);
-      }
-
-    if(m_current_particle->get_log_posterior()>m_MAP->get_log_posterior()){
-      delete m_MAP;
-
-      m_MAP=copy_particle(m_current_particle);
-      }*/
-
-    if(m_importance_sampling && m_iters>0){
-      if(m_iters == 1 || m_accept ){
-        calculate_importance_weight();
-        m_current_particle->set_weight(m_current_log_importance_weight);
-        m_current_importance_weight = exp(m_current_log_importance_weight);
-      }
-      m_sum_importance_weights += m_current_importance_weight;
-      if(!(m_iters%m_thinning))
-        m_sum_thinned_importance_weights += m_current_importance_weight;
-    }
-
-    if(m_count_dimension_frequencies && m_iters>0)
-      update_dimension_distribution();
-
-    if(m_iters>0 && m_iters%m_thinning==0)
-    {
-      if(m_mean_function_of_interest){
-
-	update_primary_function_of_interest();
-	if(m_calculating_divergence){
-	  m_mean_var_function_of_interest = 0;
-	  for(unsigned int i = 0; i < m_length_grid; i++ ){
-	    double var_mean_i =  (m_mean_sq_function_of_interest[i] - m_mean_function_of_interest[i]*(m_mean_function_of_interest[i]/n_iters))/(n_iters-1);
-	    double mean_var_i = m_var_function_of_interest[i]/n_iters;
-	    m_mean_var_function_of_interest += var_mean_i + mean_var_i;
-	  }
-	  m_mean_var_function_of_interest /= m_length_grid;
-	  m_histogram->set_divergence_var(m_mean_var_function_of_interest);
-	}
-      }
-      if(m_calculate_function && !m_storing_sample){
-	calculate_function_of_interest();
-      }
-    }
-
-    if(m_calculate_sample_histogram && m_iters>0)
-      update_histograms();
-
-
-    if(m_calculate_div && m_iters>0 && m_iters%m_thinning==0){
-
-      if(n_iters%(m_initial_iterations)==0){
-	m_size_of_sample=n_iters;
-	m_continue_loop=0;
-	if(first){
-	  m_initial_iterations=1;
-	  first=0;
-	}
-      }
-  }
-
-
-
-    m_iters++;
-
-    //	cout<<m_iters<<endl;
-
-    if(m_iters>m_iterations*m_thinning){
-      // cout<<i<<endl;
-      m_continue_loop=0;
-    }
-
-  }
-
-  //end_time=time(&end_time);
-
-  //double dif = difftime(end_time,start_time);
-
-  //cout<<difftime<<endl;;
-
-}
-
-
-template<class T>
-  void rj<T>::initiate_sample(Particle<T> * ptr2particle){
-  if (ptr2particle==NULL){
-    m_current_particle = new Particle<T>(0,NULL);
-  }
-  else{
-    m_current_particle = ptr2particle;
-  }
-
-}
-
-
-template<class T>
-  Particle<T> * rj<T>::copy_particle(Particle<T> * ptr2particle){
-
-  Particle<T> * new_particle;
-  new_particle = new Particle<T>(ptr2particle,NULL);
-  return(new_particle);
-}
-
-template<class T>
-  double rj<T>::birth_proposal(unsigned int k) const{
-  double b;
-
-  if (k==0){
-    b=1;
-  }
-  else if(k==m_max_theta){
-    b=0;
-  }
-  else{
-    b=ONE_THIRD;
-  }
-
-  return (b);
-}
-
-template<class T>
-  double rj<T>::death_proposal(unsigned int k) const {
-  double d;
-
-  if (k==0){
-    d=0;
-  }
-  else if(k==m_max_theta){
-    d=0.5;
-  }
-  else{
-    d=ONE_THIRD;
-  }
-
-  return (d);
-}
-
-template<class T>
-  double rj<T>::move_proposal(unsigned int k) const{
-
-  double m;
-
-  if (k==0){
-    m=0;
-  }
-  else if(k==m_max_theta){
-    m=0.5;
-  }
-  else{
-    m=ONE_THIRD;
-  }
-
-  return (m);
-}
-
-
-template<class T>
-  void rj<T>::update_log_posterior(){
-  m_current_particle->set_log_posterior(m_current_particle->get_log_posterior()+m_log_posterior_ratio);
-}
-
-
-template<class T>
-  void rj<T>::destroy_sample(){
-
-  for (long long int i=m_size_of_sample-1; i>0; i--){
-
-    if (m_sample[i]!=m_sample[i-1]){
-      delete m_sample[i];
-    }
-  }
-
-
-  if( m_sample[0] != m_current_particle )
-    delete m_sample[0];
-
-}
-
-
-
-template<class T>
-  void rj<T>::open_sample_stream(){
-  m_sample_stream.open(m_sample_filename.c_str(),ios::out);
-  if(!m_sample_stream){
-    cerr<<"File could not be opened"<<endl;
-    exit(1);
-  }
-  m_sample_stream<<setiosflags(ios::fixed);
-  m_sample_stream.precision(5);
-}
-
-template<class T>
-  void rj<T>::print_sample(){
-
-  open_sample_stream();
-  cout<<m_size_of_sample<<endl;
-  for(long long int i=0; i<m_size_of_sample; i++){
-      m_sample_stream<<*m_sample[i]<<endl;
-    // m_sample_stream<<*m_sample[i]<<" ";
-  }
-  m_sample_stream.close();
-}
-
-template<class T>
-  void rj<T>::open_size_of_sample_stream(){
-
-  m_sample_dimensions_stream.open(m_sample_dimensions_filename.c_str(), ios::out);
-
-  if(!m_sample_dimensions_stream){
-    cerr<<"File could not be opened"<<endl;
-    exit(1);
-  }
-}
-
-template<class T>
-  void rj<T>::print_size_of_sample(){
-
-  open_size_of_sample_stream();
-  for(long long int i=0; i<m_size_of_sample; i++){
-    m_sample_dimensions_stream<<m_sample[i]->get_dim_theta()<<' ';
-  }
-
-  m_sample_dimensions_stream.close();
-}
-
-template<class T>
-  void rj<T>::open_logposterior_of_sample_stream(){
-
-  m_sample_logposterior_stream.open(m_sample_logposterior_filename.c_str(), ios::out);
-
-  if(!m_sample_logposterior_stream){
-    cerr<<"File could not be opened"<<endl;
-    exit(1);
-  }
-}
-
-template<class T>
-  void rj<T>::print_logposterior_of_sample(){
-
-  open_logposterior_of_sample_stream();
-  for(long long int i=0; i<m_size_of_sample; i++){
-    m_sample_logposterior_stream<<m_sample[i]->get_log_posterior()<<' ';
-  }
-
-  m_sample_logposterior_stream.close();
-}
-
-template<class T>
-  void rj<T>::start_printing_sample(){
-  m_printing_sample = true;
-  if(m_printing_sample_value)
-    open_sample_stream();
-  if(m_printing_sample_dimension)
-    open_size_of_sample_stream();
-  if(m_printing_sample_posterior)
-    open_logposterior_of_sample_stream();
-}
-
-template<class T>
-  void rj<T>::stop_printing_sample(){
-  m_printing_sample = false;
-  if(m_sample_stream.is_open())
-    m_sample_stream.close();
-  if(m_sample_dimensions_stream.is_open())
-    m_sample_dimensions_stream.close();
-  if(m_sample_logposterior_stream.is_open())
-    m_sample_logposterior_stream.close();
-}
-
-template<class T>
-  void rj<T>::print_current_sample(){
-  if( m_sample_stream.is_open() )
-    m_sample_stream<<*m_current_particle<<" ";
-  if( m_sample_dimensions_stream.is_open() )
-    m_sample_dimensions_stream<<m_k<<" ";//current_particle->get_dim_theta()<<" ";
-  if( m_sample_logposterior_stream.is_open() )
-    m_sample_logposterior_stream<<m_current_particle->get_log_posterior()<<" ";
-}
-
-template<class T>
-  void rj<T>::print_acceptance_rates(){
-  cout << "\nAcceptance Rates:" << endl;
-  if( m_birth_attempt )
-    cout << "\tBirth: " << m_birth_accept/(double)m_birth_attempt << endl;
-  if( m_death_attempt )
-    cout << "\tDeath: " << m_death_accept/(double)m_death_attempt << endl;
-  if( m_move_attempt )
-    cout << "\tMove:  " << m_move_accept/(double)m_move_attempt << endl;
-}
-
-template<class T>
-  void rj<T>::write_frequency_counts_to_file(const char* output_filename){
-  ofstream OutputStream(output_filename, ios::out);
-  if(!m_importance_sampling){
-      OutputStream<<setiosflags(ios::fixed);
-      OutputStream.precision((int)log10(m_iterations*m_thinning));
-      map<unsigned int,unsigned long long int>::iterator iter = m_dimension_frequency_count.begin();
-      while(iter != m_dimension_frequency_count.end()){
-          if(iter->second)
-              OutputStream << iter->first << "\t" << (double)iter->second/m_iters << endl;
-          ++iter;
-      }
-  }else{
-      map<unsigned int,long double>::iterator iter = m_dimension_frequency_weight.begin();
-      while(iter != m_dimension_frequency_weight.end()){
-          if(iter->second>0)
-              OutputStream << iter->first << "\t" << (double)iter->second/m_sum_importance_weights << endl;
-          ++iter;
-      }
-  }
-  OutputStream.close();
-}
-
-template<class T>
-void rj<T>::calculate_sample_histogram( bool mv, unsigned int num_bins, bool bounded, bool weighted_histogram, bool calculate_divergence, Divergence_Type divergence_type, Loss_Function loss_fn, unsigned int look_up_length, bool estimate_cor, unsigned int max_dim ){
-  m_calculate_sample_histogram = true;
-  if(mv)
-    m_calculate_mv_sample_histogram = true;
-  m_num_bins = num_bins;
-
-  m_bin_width = (m_end_time-m_start_cps)/m_num_bins;
-
-  if( !m_histogram ){
-    if(!calculate_divergence){
-      m_histogram = new Histogram_Type<T>( m_start_cps, m_end_time, m_num_bins, m_bin_width, bounded, weighted_histogram, m_calculate_1d_sample_histogram, max_dim );
-    }
-    else{
-      m_histogram = new Histogram_Type<T>( m_start_cps, m_end_time, m_num_bins, m_bin_width, bounded, weighted_histogram, m_calculate_1d_sample_histogram, max_dim, NULL, true, divergence_type, loss_fn, look_up_length, estimate_cor );
-      m_histogram->track_entropy();
-//      m_histogram->use_single_component();
-    }
-    set_histogram_component_value_function();
-  }
-}
-
-template<class T>
-void rj<T>::start_calculating_mc_divergence(Divergence_Type divergence_type, Loss_Function loss_fn, unsigned int num_bins, bool bounded, unsigned int look_up_length, bool estimate_cor, unsigned int max_dim){
-  m_calculating_divergence = true;
-  if(!m_calculate_sample_histogram)
-    calculate_sample_histogram(true,num_bins,bounded,false,true,divergence_type,loss_fn,look_up_length,estimate_cor,max_dim);
-  else
-    m_calculate_mv_sample_histogram = true;
-}
-
-template<class T>
-  void rj<T>::update_histograms(){
-  bool end_of_batch_should_be_new = (m_thinning>1 && m_iters%m_thinning==0) || (m_thinning==1 && m_accept );
-  bool end_of_batch = m_iters%m_thinning==0;
-  if((m_iters==1)||(m_calculate_1d_sample_histogram && m_accept)||end_of_batch_should_be_new)
-    m_histogram->calculate_bin( m_current_particle, m_k );
-  else if(m_iters>1&&(m_thinning==1 && !m_accept))
-    m_histogram->increment_num_bin_repeats();
-  if(m_calculate_mv_sample_histogram && end_of_batch)
-    m_histogram->increment_bin_counts(NULL,m_current_importance_weight);
-  if(m_calculate_1d_sample_histogram)
-    m_histogram->increment_1d_bin_counts(m_current_importance_weight);
-}
-
-template<class T>
-  double rj<T>::get_divergence(){
-  double divergence = m_histogram->get_divergence();
-  return divergence;
-}
-
-template<class T>
-  void rj<T>::write_primary_function_of_interest_to_file(const string output_filename){
-  if(!m_mean_function_of_interest)
-    return;
-  unsigned int iterations = m_iters/m_thinning;
-  ofstream OutputStream(output_filename.c_str(), ios::out);
-  for(unsigned int i = 0; i < m_length_grid; i++ ){
-    double var_mean_i = (m_mean_sq_function_of_interest[i] - m_mean_function_of_interest[i]*(m_mean_function_of_interest[i]/iterations))/(m_iters-1);
-    double mean_var_i = m_var_function_of_interest[i]/iterations;
-    OutputStream << m_mean_function_of_interest[i]/iterations << "\t" << var_mean_i + mean_var_i << endl;
-  }
-  OutputStream.close();
-}
-
-template<class T>
-  void rj<T>::update_dimension_distribution(){
-    unsigned int current_dimension = m_k;//m_current_particle->get_dim_theta();
-    if(!m_importance_sampling){
-      bool entered_new_dimension = m_dimension_frequency_count.find(current_dimension) == m_dimension_frequency_count.end();
-      if(entered_new_dimension || (m_MAPs[current_dimension]->get_log_posterior()<m_current_particle->get_log_posterior())){
-	if(!entered_new_dimension && m_MAPs[current_dimension])
-	  delete m_MAPs[current_dimension];
-	m_MAPs[current_dimension] = copy_particle(m_current_particle);
-      }
-      if(entered_new_dimension)
-        m_dimension_frequency_count[current_dimension] = 1;
-      else
-        m_dimension_frequency_count[current_dimension]++;
-      if(m_MAP_dimension != current_dimension && ((m_dimension_frequency_count.find(m_MAP_dimension)==m_dimension_frequency_count.end())|| (m_dimension_frequency_count[current_dimension]>m_dimension_frequency_count[m_MAP_dimension])))
-	m_MAP_dimension = current_dimension;
-    }
-    else{
-      bool entered_new_dimension = m_dimension_frequency_weight.find(current_dimension) == m_dimension_frequency_weight.end();
-      if(entered_new_dimension || (m_MAPs[current_dimension]->get_log_posterior()+m_MAPs[current_dimension]->get_weight()<m_current_particle->get_log_posterior()+m_current_particle->get_weight())){
-        if(!entered_new_dimension && m_MAPs[current_dimension])
-	  delete m_MAPs[current_dimension];
-	m_MAPs[current_dimension] = copy_particle(m_current_particle);
-      }
-      if(entered_new_dimension)
-	m_dimension_frequency_weight[current_dimension] = m_current_importance_weight;
-      else
-	m_dimension_frequency_weight[current_dimension] += m_current_importance_weight;
-      if(m_MAP_dimension != current_dimension && ((m_dimension_frequency_weight.find(m_MAP_dimension)==m_dimension_frequency_weight.end())|| (m_dimension_frequency_weight[current_dimension]>m_dimension_frequency_weight[m_MAP_dimension])))
-	m_MAP_dimension = current_dimension;
-    }
-}
-#endif
-


added ConfigWithLogger which allows to specify a custom logger implementation

Change-Id: Ia6b9c81f2b6f71ba00001eecf8aa0bf0c70fe8b1

error: pathspec 'src/ConfigWithLogger.h' did not match any file(s) known to git

--- src/ConfigWithLogger.h
+++ src/ConfigWithLogger.h
@@ -0,0 +1,41 @@
+/*
+ * #%L
+ * %%
+ * Copyright (C) 2017 BMW Car IT GmbH
+ * %%
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * #L%
+ */
+
+#ifndef WSCPP_CONFIGWITHLOGGER_H
+#define WSCPP_CONFIGWITHLOGGER_H
+
+#include <websocketpp/config/core_client.hpp>
+#include <websocketpp/transport/asio/endpoint.hpp>
+
+template <typename Logger, typename Socket>
+struct ConfigWithLogger : public websocketpp::config::core_client {
+
+  using alog_type = Logger;
+  using elog_type = Logger;
+
+  struct transport_config : public core_client::transport_config {
+    using alog_type = Logger;
+    using elog_type = Logger;
+    using socket_type = Socket;
+  };
+
+  using transport_type = websocketpp::transport::asio::endpoint<transport_config>;
+};
+
+#endif // WSCPP_CONFIGWITHLOGGER_H


version 1.999.121rc2

version 1.999.121rc2

--- misc/version.h
+++ misc/version.h
@@ -35,7 +35,7 @@
 #define BADVPN_MISC_VERSION_H

 #define GLOBAL_PRODUCT_NAME "BadVPN"
-#define GLOBAL_VERSION "1.999.121rc1"
+#define GLOBAL_VERSION "1.999.121rc2"
 #define GLOBAL_COPYRIGHT_NOTICE "Copyright (C) 2010 Ambroz Bizjak <ambrop7@gmail.com>"

 #endif


EmulatorPkg/FvbServicesRuntimeDxe: correct NumOfLba vararg type in EraseBlocks()

According to the PI spec, Volume 3,
EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL.EraseBlocks():

> The variable argument list is a list of tuples. Each tuple describes a
> range of LBAs to erase and consists of the following:
> * An EFI_LBA that indicates the starting LBA
> * A UINTN that indicates the number of blocks to erase

(NB, in edk2, EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL is a typedef to
EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL.)

In this driver, the NumOfLba local variable is defined with type UINTN,
but the TYPE argument passed to VA_ARG() is UINT32. Fix the mismatch.

Cc: Andrew Fish <be8d29debaaf5173b4b7ecb4ace852732e71f7b9@apple.com>
Cc: Jordan Justen <a79006884ba9cf5f4f7fcbb92a15b208780d8c97@intel.com>
Reported-by: Jordan Justen <a79006884ba9cf5f4f7fcbb92a15b208780d8c97@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Laszlo Ersek <7437296077edea1cb64451c122c4dac071f0cfbc@redhat.com>
Reviewed-by: Jordan Justen <a79006884ba9cf5f4f7fcbb92a15b208780d8c97@intel.com>

--- EmulatorPkg/FvbServicesRuntimeDxe/FWBlockService.c
+++ EmulatorPkg/FvbServicesRuntimeDxe/FWBlockService.c
@@ -906,7 +906,7 @@
       break;
     }

-    NumOfLba = VA_ARG (args, UINT32);
+    NumOfLba = VA_ARG (args, UINTN);

     //
     // Check input parameters
@@ -926,7 +926,7 @@
       break;
     }

-    NumOfLba = VA_ARG (args, UINT32);
+    NumOfLba = VA_ARG (args, UINTN);

     while (NumOfLba > 0) {
       Status = FvbEraseBlock (FvbDevice->Instance, StartingLba, mFvbModuleGlobal, EfiGoneVirtual ());


nffs - blocks were missing from end of files.

There was a bug in how nffs determines which block comes last in a file
inode.  This process is still horribly inefficient (MYNEWT-161), but it
should at least work now.

--- fs/nffs/src/nffs_restore.c
+++ fs/nffs/src/nffs_restore.c
@@ -218,6 +218,76 @@
     out_inode->ni_inode_entry = inode_entry;
 }

+static int
+nffs_restore_find_file_end_block(struct nffs_hash_entry *block_entry)
+{
+    struct nffs_inode_entry *inode_entry;
+    struct nffs_block block;
+    int rc;
+
+    rc = nffs_block_from_hash_entry(&block, block_entry);
+    assert(rc == 0);
+
+    inode_entry = block.nb_inode_entry;
+
+    /* Make sure the parent inode (file) points to the latest data block
+     * restored so far.
+     *
+     * XXX: This is an O(n) operation (n = # of blocks in the file), and is
+     * horribly inefficient for large files.  MYNEWT-161 has been opened to
+     * address this.
+     */
+    if (inode_entry->nie_last_block_entry == NULL) {
+        /* This is the first data block restored for this file. */
+        inode_entry->nie_last_block_entry = block_entry;
+        NFFS_LOG(DEBUG, "setting last block: %u\n", block_entry->nhe_id);
+    } else {
+        /* Determine if this this data block comes after our current idea of
+         * the file's last data block.
+         */
+
+        rc = nffs_block_find_predecessor(
+            block_entry, inode_entry->nie_last_block_entry->nhe_id);
+        switch (rc) {
+        case 0:
+            /* The currently-last block is a predecessor of the new block; the
+             * new block comes later.
+             */
+            NFFS_LOG(DEBUG, "replacing last block: %u --> %u\n",
+                     inode_entry->nie_last_block_entry->nhe_id,
+                     block_entry->nhe_id);
+            inode_entry->nie_last_block_entry = block_entry;
+            break;
+
+        case FS_ENOENT:
+            break;
+
+        default:
+            return rc;
+        }
+    }
+
+    return 0;
+}
+
+
+static int
+nffs_restore_find_file_ends(void)
+{
+    struct nffs_hash_entry *block_entry;
+    int rc;
+    int i;
+
+    NFFS_HASH_FOREACH(block_entry, i) {
+        if (!nffs_hash_id_is_inode(block_entry->nhe_id)) {
+            rc = nffs_restore_find_file_end_block(block_entry);
+            assert(rc == 0);
+        }
+    }
+
+    return 0;
+}
+
 /**
  * Performs a sweep of the RAM representation at the end of a successful
  * restore.  The sweep phase performs the following actions of each inode in
@@ -483,13 +553,13 @@
     }

     if (nffs_hash_id_is_file(inode_entry->nie_hash_entry.nhe_id)) {
-        NFFS_LOG(DEBUG, "restoring file; id=%d\n",
+        NFFS_LOG(DEBUG, "restoring file; id=0x%08x\n",
                  inode_entry->nie_hash_entry.nhe_id);
         if (inode_entry->nie_hash_entry.nhe_id >= nffs_hash_next_file_id) {
             nffs_hash_next_file_id = inode_entry->nie_hash_entry.nhe_id + 1;
         }
     } else {
-        NFFS_LOG(DEBUG, "restoring dir; id=%d\n",
+        NFFS_LOG(DEBUG, "restoring dir; id=0x%08x\n",
                  inode_entry->nie_hash_entry.nhe_id);
         if (inode_entry->nie_hash_entry.nhe_id >= nffs_hash_next_dir_id) {
             nffs_hash_next_dir_id = inode_entry->nie_hash_entry.nhe_id + 1;
@@ -619,7 +689,7 @@
         nffs_restore_largest_block_data_len = disk_block->ndb_data_len;
     }

-    NFFS_LOG(DEBUG, "restoring block; id=%u seq=%u inode_id=%u prev_id=%u "
+    NFFS_LOG(DEBUG, "restoring block; id=0x%08x seq=%u inode_id=%u prev_id=%u "
              "data_len=%u\n", disk_block->ndb_id, disk_block->ndb_seq,
              disk_block->ndb_inode_id, disk_block->ndb_prev_id,
              disk_block->ndb_data_len);
@@ -632,59 +702,6 @@
         }
     }

-    /* Make sure the parent inode (file) points to the latest data block
-     * restored so far.
-     *
-     * XXX: This is an O(n) operation (n = # of blocks in the file), and is
-     * horribly inefficient for large files.  MYNEWT-161 has been opened to
-     * address this.
-     */
-    if (inode_entry->nie_last_block_entry == NULL) {
-        /* This is the first data block restored for this file. */
-        inode_entry->nie_last_block_entry = entry;
-        NFFS_LOG(DEBUG, "setting last block: %u\n", entry->nhe_id);
-    } else {
-        /* Determine if this this data block comes after our current idea of
-         * the file's last data block.
-         */
-
-        rc = nffs_block_find_predecessor(
-            entry, inode_entry->nie_last_block_entry->nhe_id);
-        switch (rc) {
-        case 0:
-            /* The currently-last block is a predecessor of the new block; the
-             * new block comes later.
-             */
-            NFFS_LOG(DEBUG, "replacing last block: %u --> %u\n",
-                     inode_entry->nie_last_block_entry->nhe_id,
-                     entry->nhe_id);
-            inode_entry->nie_last_block_entry = entry;
-            break;
-
-        case FS_ENOENT:
-            /* The currently-last block is not a known predecessor of the new
-             * block.  There are two possibilities:
-             *     (1) The new block comes before the currently-last block.
-             *     (2) The new block comes later, but the two blocks are not
-             *         chained in RAM yet because an intervening block has yet
-             *         to be restored.
-             * If we can find the new block by searching backwards from the
-             * currently-last black, then (1) is true.  Otherwise, (2) is true.
-             */
-            rc = nffs_block_find_predecessor(
-                inode_entry->nie_last_block_entry, entry->nhe_id);
-            if (rc == FS_ENOENT) {
-                inode_entry->nie_last_block_entry = entry;
-                NFFS_LOG(DEBUG, "replacing last block: %u --> %u\n",
-                         inode_entry->nie_last_block_entry->nhe_id,
-                         entry->nhe_id);
-            }
-            break;
-
-        default:
-            return rc;
-        }
-    }

     return 0;

@@ -1135,6 +1152,9 @@
         goto err;
     }

+    /* Find the last block in each file inode. */
+    nffs_restore_find_file_ends();
+
     /* Delete from RAM any objects that were invalidated when subsequent areas
      * were restored.
      */


extra endif

extra endif

--- src/nwpw/nwpwlib/utilities/nwpw_talker.c
+++ src/nwpw/nwpwlib/utilities/nwpw_talker.c
@@ -13,7 +13,6 @@
 #include <sys/socket.h>
 #include <netinet/in.h>
 #include <arpa/inet.h>
-#endif
 #include <netdb.h>
 #endif
 #include "typesf2c.h"


ocfs2: handle network errors during recovery

Signed-off-by: Kurt Hackel <4f2d60318113bca466b89f6a1ac29843222d51ee@oracle.com>
Signed-off-by: Mark Fasheh <3dfef03b24d35cb667816693d0487c922cd46885@oracle.com>

--- fs/ocfs2/dlm/dlmrecovery.c
+++ fs/ocfs2/dlm/dlmrecovery.c
@@ -757,6 +757,7 @@
 	struct list_head *iter;
 	int ret;
 	u8 dead_node, reco_master;
+	int skip_all_done = 0;

 	dlm = item->dlm;
 	dead_node = item->u.ral.dead_node;
@@ -793,12 +794,18 @@
 	dlm_move_reco_locks_to_list(dlm, &resources, dead_node);

 	/* now we can begin blasting lockreses without the dlm lock */
+
+	/* any errors returned will be due to the new_master dying,
+	 * the dlm_reco_thread should detect this */
 	list_for_each(iter, &resources) {
 		res = list_entry (iter, struct dlm_lock_resource, recovering);
 		ret = dlm_send_one_lockres(dlm, res, mres, reco_master,
 				   	DLM_MRES_RECOVERY);
-		if (ret < 0)
+		if (ret < 0) {
 			mlog_errno(ret);
+			skip_all_done = 1;
+			break;
+		}
 	}

 	/* move the resources back to the list */
@@ -806,9 +813,12 @@
 	list_splice_init(&resources, &dlm->reco.resources);
 	spin_unlock(&dlm->spinlock);

-	ret = dlm_send_all_done_msg(dlm, dead_node, reco_master);
-	if (ret < 0)
-		mlog_errno(ret);
+	if (!skip_all_done) {
+		ret = dlm_send_all_done_msg(dlm, dead_node, reco_master);
+		if (ret < 0) {
+			mlog_errno(ret);
+		}
+	}

 	free_page((unsigned long)data);
 }
@@ -828,8 +838,14 @@

 	ret = o2net_send_message(DLM_RECO_DATA_DONE_MSG, dlm->key, &done_msg,
 				 sizeof(done_msg), send_to, &tmpret);
-	/* negative status is ignored by the caller */
-	if (ret >= 0)
+	if (ret < 0) {
+		if (!dlm_is_host_down(ret)) {
+			mlog_errno(ret);
+			mlog(ML_ERROR, "%s: unknown error sending data-done "
+			     "to %u\n", dlm->name, send_to);
+			BUG();
+		}
+	} else
 		ret = tmpret;
 	return ret;
 }
@@ -1109,22 +1125,25 @@
 			 * we must send it immediately. */
 			ret = dlm_send_mig_lockres_msg(dlm, mres, send_to,
 						       res, total_locks);
-			if (ret < 0) {
-				// TODO
-				mlog(ML_ERROR, "dlm_send_mig_lockres_msg "
-				     "returned %d, TODO\n", ret);
-				BUG();
-			}
+			if (ret < 0)
+				goto error;
 		}
 	}
 	/* flush any remaining locks */
 	ret = dlm_send_mig_lockres_msg(dlm, mres, send_to, res, total_locks);
-	if (ret < 0) {
-		// TODO
-		mlog(ML_ERROR, "dlm_send_mig_lockres_msg returned %d, "
-		     "TODO\n", ret);
+	if (ret < 0)
+		goto error;
+	return ret;
+
+error:
+	mlog(ML_ERROR, "%s: dlm_send_mig_lockres_msg returned %d\n",
+	     dlm->name, ret);
+	if (!dlm_is_host_down(ret))
 		BUG();
-	}
+	mlog(0, "%s: node %u went down while sending %s "
+	     "lockres %.*s\n", dlm->name, send_to,
+	     flags & DLM_MRES_RECOVERY ?  "recovery" : "migration",
+	     res->lockname.len, res->lockname.name);
 	return ret;
 }


ocfs2: remove bogus check in dlm_process_recovery_data

In dlm_process_recovery_data, only when dlm_new_lock failed the ret will
be set to -ENOMEM.  And in this case, newlock is definitely NULL.  So
test newlock is meaningless, remove it.

Signed-off-by: Joseph Qi <88260f35dd98758635dbbf2145383e817a86f01c@huawei.com>
Reviewed-by: Alex Chen <4ac5dc52b5921607e5d8c9db7ef74df83bd6110b@huawei.com>
Reviewed-by: Mark Fasheh <8f0bc92cac940f3e83deb53ced7a1f201bce5732@suse.de>
Cc: Joel Becker <9d3d88cacb47f143c6cf36b9a61c09b528b2c49a@evilplan.org>
Signed-off-by: Andrew Morton <5c1e68b099950c134891f0b6e179498a8ebe9cf9@linux-foundation.org>
Signed-off-by: Linus Torvalds <69652caca27c8b940640ad396ab71f93cacec34f@linux-foundation.org>