--- ./source/private_module/vol/vol_res/vol_res_alloc.c	2018-05-07 11:20:51.000000000 +0000
+++ ./source/private_module/vol/vol_res/vol_res_alloc.c.hotpatch	2020-02-10 17:16:45.000000000 +0000
@@ -14486,14 +14486,14 @@
 
 }
 
-/**************************************************************************
-     :  volume reqɺĻص
- :  req: ڵȵREQ
-            externReq:extentĶд
- :  
- ֵ  :  
-     :  
-**************************************************************************/
+void resChildReqDoneForPatch(REQ_S * req,REQ_S * extentReq);
+extern void enterResFormatTaskForPatch(void);
+extern bool g_enterFormatPatchFunc;
+
+
+
+
+
 void resChildReqDone(REQ_S *req, REQ_S *extentReq)
 {
     META_VOLUME_CTRL_S         *volCtrl;
@@ -14506,7 +14506,7 @@
     uint32_t                   grainSize;
     bool                       reenterFormat;
 
-    //VOLS_BUG_HANDLE(NULL != extentReq);
+    if (g_enterFormatPatchFunc) {resChildReqDoneForPatch(req, extentReq);return;}
 
     /* ȡreqеڴϢ */
     context = (RES_ALLOC_TASK_CONTEXT_S *)
@@ -20698,7 +20698,7 @@
     spin_unlock(&format->lock);
 
     if (needStart)
-    {
+    {   if (g_enterFormatPatchFunc) {enterResFormatTaskForPatch();return;}
         enterResFormatTask();
     }
 }
@@ -22845,5 +22845,228 @@
 EXPORT_SYMBOL(checkIsVolHasCowGrainInVolMgr);
 /* ҵлԪ̣x900062562017/5/5end */
 
+extern uint64_t g_idleCnt1;
+extern uint64_t g_idleCnt2;
+extern uint64_t g_formatStopCnt;
+extern bool g_isFormatRunning;
+extern bool g_needReenter;
+
+void enterResFormatTaskForPatch(void)
+{
+    RES_FORMAT_S               *format;
+    REQ_S                      *req;
+    REQ_S                      *nextHeadReq;
+    struct list_head           *head;
+    RES_ALLOC_TASK_CONTEXT_S   *context;
+    RES_REALLOC_TASK_CONTEXT_S *reAllocContext;
+    uint32_t                   reqCap;
+    int32_t                    result;
+    REQ_S                      *reqHead;
+
+    format = &g_resFormat;
+    spin_lock(&format->lock);
+    if (g_isFormatRunning)
+    {
+        spin_unlock(&format->lock);
+        return;
+    }
+    g_isFormatRunning = TRUE;
+    spin_unlock(&format->lock);
+
+    head = &format->head;
+    format->extentReqHead = NULL;
+    format->extentReqTail = NULL;
+    format->reqReqCap     = 0;
+    format->finReqCap     = 0;
+
+    do
+    {
+        req = format->leftReq;
+        format->leftReq = NULL;
+        if (NULL == req)
+        {
+            spin_lock(&format->lock);
+            if (0 != format->num)
+            {
+                req = list_entry(head->next, REQ_S, childNode);
+                list_del(&req->childNode);
+                format->num--;
+            }
+            else
+            {
+                g_isFormatRunning = FALSE;
+                format->isInProcess = FALSE;
+                spin_unlock(&format->lock);
+                return;
+            }
+            spin_unlock(&format->lock);
+
+            result = formatGrainForReAlloc(req);
+            if (RETURN_OK != result)
+            {
+                req->result = RETURN_ERROR;
+                START_CALLBACK_REQ(req);
+
+                VOL_PRINT_LIMIT_PERIOD(VOL_LOG_CTRL_INTERVAL, VOL_LOG_CTRL_COUNT,
+                    DBG_LOG_ERROR, VOL_LOG_ID_08F7,
+                    "Volume get format req list failed. ");
+
+                continue;
+            }
+        }
+
+        context = (RES_ALLOC_TASK_CONTEXT_S *)GET_USER_BUFF(req, sizeof(RES_ALLOC_TASK_CONTEXT_S));
+        reAllocContext = &context->reAllocContext;
+        reqCap = reAllocContext->reqCap;
+
+        if (format->threshold >= format->reqReqCap + reqCap)
+        {
+            format->reqReqCap += reqCap;
+            reAllocContext->reqCap = 0;
+            if (format->threshold == format->reqReqCap)
+            {
+                spin_lock(&format->lock);
+                g_isFormatRunning = FALSE;
+                g_idleCnt1++;
+                g_needReenter = TRUE;
+                spin_unlock(&format->lock);
+
+                execResFormating(reAllocContext->reqHead);                
+                return;
+            }
+            else
+            {
+                execResFormating(reAllocContext->reqHead);
+            }
+        }
+        else
+        {
+            nextHeadReq = divideFormatReq(format, reAllocContext);
+            reqHead = reAllocContext->reqHead;
+            reAllocContext->reqHead = nextHeadReq;
+
+            /* nextHeadReqΪգ˵Ҫ·ĸʽIOΪ˵λὫеĸʽ·
+             * ʽIOɺreqᱻͷŵﲻܽ仹leftReqϣ
+             */
+            if (NULL != nextHeadReq)
+            {
+                format->leftReq = req;                
+            }
+
+            spin_lock(&format->lock);
+            g_isFormatRunning = FALSE;
+            g_idleCnt2++;
+            g_needReenter = TRUE;
+            spin_unlock(&format->lock);
+
+            execResFormating(reqHead);
+            return;
+        }
+    }while(format->isInProcess);
+
+    spin_lock(&format->lock);
+    g_formatStopCnt++;
+    g_isFormatRunning = FALSE;
+    spin_unlock(&format->lock);
+    return;
+}
+
+void resChildReqDoneForPatch(REQ_S *req, REQ_S *extentReq)
+{
+    META_VOLUME_CTRL_S         *volCtrl;
+    META_RES_MGR_S             *metaMgr;
+    RES_ALLOC_TASK_CONTEXT_S   *context;
+    RES_REALLOC_TASK_CONTEXT_S *reAllocContext;
+    RES_ALLOC_TASK_S           *allocTask;
+    RES_FORMAT_S               *format;
+    uint32_t                   extentReqLength;
+    uint32_t                   grainSize;
+    bool                       reenterFormat;
+
+    //VOLS_BUG_HANDLE(NULL != extentReq);
+
+    /* ȡreqеڴϢ */
+    context = (RES_ALLOC_TASK_CONTEXT_S *)
+        GET_USER_BUFF(req, sizeof(RES_ALLOC_TASK_CONTEXT_S));
+
+    reAllocContext = &context->reAllocContext;
+    metaMgr        = context->metaMgr;
+    volCtrl        = (META_VOLUME_CTRL_S* )metaMgr->metaVolObj;
+    allocTask      = &metaMgr->resMgr->resAlloc.allocTask;
+
+    /* ȡgrain size, grain sizeͰdata,cow */
+    grainSize = RES_GRAIN_SIZE(metaMgr, volCtrl);
+    spin_lock(&allocTask->lock);
+
+    extentReqLength = extentReq->length;
+    reAllocContext->finFormatNum += extentReq->length / grainSize;
+    /* extent reqʧܾҪøreq meta req*/
+    if (unlikely(RETURN_OK != extentReq->result))
+    {
+        req->result = extentReq->result;
+    }
+
+    /* log ͷreq */
+    REQ_DELETE(extentReq);
+
+    format = &g_resFormat;
+    spin_lock(&format->lock);
+    format->finReqCap += RES_GET_FORMAT_CAP(extentReqLength);
+    reenterFormat = FALSE;
+    if (format->threshold <= format->finReqCap)
+    {
+        g_needReenter = FALSE;
+        reenterFormat = TRUE;
+    }
+    spin_unlock(&format->lock);
+
+    if (TRUE == reenterFormat)
+    {
+        enterResFormatTaskForPatch();
+    }
+
+    if (reAllocContext->finFormatNum == reAllocContext->grainNum)
+    {
+        spin_unlock(&allocTask->lock);
+
+        /* ͳƽ */
+        VOLS_COUNTER_LATENCY_INC(VOL_COUNTER_RES_FORMAT_GRAINS,
+            VOLS_DEBUG_RES_COUNTER, LVOS_GetMilliSecond() - context->latency);
+        VOLS_COUNTER_BACK_INC(VOL_COUNTER_RES_FORMAT_GRAINS,
+            VOLS_DEBUG_RES_COUNTER, req->result);
+
+        /* жϸʽǷȫɹ
+        */
+        if (unlikely(RETURN_OK != req->result))
+        {
+            /*  */
+            DBG_RES_STEP(allocTask->dbgFlag, DBG_FORMAT_GRAIN_DONE_ERR);
+
+            START_CALLBACK_REQ(req);
+
+            return;
+        }
+        /*DTS2014052008027, άǿ w00251485, 2014/05/20, begin*/
+        /*ͷҳͳ*/
+        VOL_RES_PAGE_FREE_INC(req->sgl->entrySumInChain);
+        /*DTS2014052008027, άǿ w00251485, 2014/05/20, end*/
+
+        FREE_PAGES_AND_SGL(volCtrl->volId, volCtrl->volId, req->sgl,
+            PAGE_USAGE_VOLUME_WRITE_ZERO);
+        req->sgl = NULL;
+
+        /* ִһ */
+        START_CALLBACK_REQ(req);
+    }
+    else
+    {
+        spin_unlock(&allocTask->lock);
+    }
+
+    return;
+}
+
+
+
 
 /* EOF */
--- ./source/private_module/vol/vol_res/vol_res_diagnose.c	2018-04-03 02:27:46.000000000 +0000
+++ ./source/private_module/vol/vol_res/vol_res_diagnose.c.hotpatch	2020-02-10 17:16:45.000000000 +0000
@@ -7227,13 +7227,13 @@
 
     return;
 }
-/*******************************************************************************
-     :  ʾRESԴ̨ʽ״̬
- :  
- :  
- ֵ  :  
-     :  
-*******************************************************************************/
+uint64_t g_idleCnt1 = 0;
+uint64_t g_idleCnt2 = 0;
+uint64_t g_formatStopCnt = 0;
+bool g_isFormatRunning = FALSE;
+bool g_needReenter = FALSE;
+bool g_enterFormatPatchFunc = TRUE;
+
 void diagShowResFormatInfo(int32_t argc, char* on)
 {
     RES_FORMAT_S format;
@@ -7250,27 +7250,28 @@
         DBG_Print("  Usage: volume showresformatinfo [on|off]\n");
         return;
     }
-
     if ((3 == argc) && (0 != strcmp(on, "on")) && (0 != strcmp(on, "off")))
     {
         DBG_Print("  Input is illegal.\n");
         DBG_Print("  Usage: volume showresformatinfo [on|off]\n");
         return;
     }
-
     spin_lock(&g_resFormat.lock);
     memcpy(&format, &g_resFormat, sizeof(RES_FORMAT_S));
     spin_unlock(&g_resFormat.lock);
-
     DBG_Print("Format info when reAlloc:\n");
     DBG_Print(  "  State                            : %s\n",
             (format.isInProcess == TRUE) ? "Processing" : "Idle");
     DBG_Print(  "  Req num                          : %u\n", format.num);
     DBG_Print(  "  Threshold                        : %u\n", format.threshold);
     DBG_Print(  "  Current Send Cap                 : %u\n", format.reqReqCap);
-    DBG_Print(  "  Finished Cap                     : %u\n", format.finReqCap);
+    DBG_Print(  "  Finished Cap                     : %u\n", format.finReqCap);    
+    DBG_Print(  "  Idle Count 1                     : %llu\n", g_idleCnt1);    
+    DBG_Print(  "  Idle Count 2                     : %llu\n", g_idleCnt2);
+    DBG_Print(  "  Need Reenter                     : %d\n",   g_needReenter);    
+    DBG_Print(  "  Is Format Task Running           : %d\n",   g_isFormatRunning);    
+    DBG_Print(  "  Format Stop cnt                  : %llu\n", g_formatStopCnt);
     DBG_Print("\n");
-
     if (0 == strcmp(on, "on"))
     {
         spin_lock(&g_resFormat.lock);
@@ -7295,7 +7296,6 @@
         }
     }
     DBG_Print("\n");
-
     return;
 }
 /*******************************************************************************
