private void do_inode_refupdate_work(UpdateReqI cu, int childcnt) { byte[] buffer = new byte[4096]; lock (tfile0) { tfile0.Seek((long)cu.tfbn * 4096, SeekOrigin.Begin); tfile0.Read(tmpiodatatfileR, 0, 4096); CONFIG.Decrypt_Read_WRBuf(tmpiodatatfileR, buffer); //DEFS.DEBUG("ENCY", "READ inoLo : " + OPS.ChecksumPageWRLoader(buffer)); DEFS.DEBUG("CNTR", "do_inode_refupdate_work (" + cu.tfbn + ") childcnt =" + childcnt); } /* * Parent of inowip is always -1. */ RedFS_Inode wip = new RedFS_Inode(WIP_TYPE.REGULAR_FILE, 0, -1); byte[] buf = new byte[128]; for (int i = 0; i < 32; i++) { for (int t = 0; t < 128; t++) { buf[t] = buffer[i * 128 + t]; } wip.parse_bytes(buf); BLK_TYPE type = BLK_TYPE.IGNORE; int numidx = 0; switch (wip.get_inode_level()) { case 0: type = BLK_TYPE.REGULAR_FILE_L0; numidx = OPS.NUML0(wip.get_filesize()); break; case 1: type = BLK_TYPE.REGULAR_FILE_L1; numidx = OPS.NUML1(wip.get_filesize()); break; case 2: type = BLK_TYPE.REGULAR_FILE_L2; numidx = OPS.NUML2(wip.get_filesize()); break; } for (int x = 0; x < numidx; x++) { int dbn = wip.get_child_dbn(x); //if (dbn <= 0) continue; DEFS.DEBUGCLR("^^^^^", "wip[" + x + "] " + dbn + "," + wip.get_wiptype() + "," + childcnt + " fsize = " + wip.get_filesize()); DEFS.DEBUGCLR("@@@", wip.get_string_rep2()); apply_update_internal(dbn, type, childcnt, cu.optype, true); } } OPS.dump_inoL0_wips(buffer); }
/* * Given a dbn, load the appropriate block and apply the update. */ private void apply_update_internal(int dbn, BLK_TYPE type, int value, REFCNT_OP optype, bool updatechild) { int rbn = REFDEF.dbn_to_rbn(dbn); load_wrbufx(rbn); counter++; int curr = GLOBALQ.WRObj[rbn].incoretbuf.get_refcount(dbn); GLOBALQ.WRObj[rbn].incoretbuf.set_refcount(dbn, curr + value); if (optype == REFCNT_OP.INCREMENT_REFCOUNT_ALLOC || optype == REFCNT_OP.DECREMENT_REFCOUNT_ONDEALLOC) { //DEFS.DEBUG("DSAF", "Apply update internal, " + optype + " : " + dbn + "," + value + "," + updatechild); GLOBALQ.WRObj[rbn].incoretbuf.set_dedupe_overwritten_flag(dbn, true); } if (updatechild) { if (type != BLK_TYPE.REGULAR_FILE_L0 && type != BLK_TYPE.IGNORE) { int currchd = GLOBALQ.WRObj[rbn].incoretbuf.get_childcount(dbn); GLOBALQ.WRObj[rbn].incoretbuf.set_childcount(dbn, currchd + value); DEFS.DEBUGCLR("/-0-0-/", "dbn, " + dbn + "(" + curr + "->" + (curr + value) + ") (" + currchd + "->" + (currchd + value) + ")"); } } }
private Red_Buffer allocate_wb(BLK_TYPE type) { Red_Buffer wb = null; switch (type) { case BLK_TYPE.REGULAR_FILE_L1: wb = new RedBufL1(0); break; case BLK_TYPE.REGULAR_FILE_L2: wb = new RedBufL2(0); break; } DEFS.ASSERT(wb != null, "Wrong request for allocate_wb(), type = " + type); return(wb); }
private void do_regular_dirORfile_work(UpdateReqI cu, int childcnt) { Red_Buffer wb = allocate_wb(cu.blktype); byte[] buffer = new byte[4096]; lock (tfile0) { tfile0.Seek((long)cu.tfbn * 4096, SeekOrigin.Begin); tfile0.Read(tmpiodatatfileR, 0, 4096); CONFIG.Decrypt_Read_WRBuf(tmpiodatatfileR, buffer); //DEFS.DEBUG("ENCY", "READ RF : " + OPS.ChecksumPageWRLoader(buffer)); DEFS.DEBUG("CNTR", "do_regular_dirORfile_work (" + cu.tfbn + ") childcnt =" + childcnt); } wb.data_to_buf(buffer); REDFS_BUFFER_ENCAPSULATED wbe = new REDFS_BUFFER_ENCAPSULATED(wb); BLK_TYPE belowtype = BLK_TYPE.IGNORE; switch (cu.blktype) { case BLK_TYPE.REGULAR_FILE_L1: belowtype = BLK_TYPE.REGULAR_FILE_L0; break; case BLK_TYPE.REGULAR_FILE_L2: belowtype = BLK_TYPE.REGULAR_FILE_L1; break; } for (int i = 0; i < 1024; i++) { int dbnt = wbe.get_child_dbn(i); if (dbnt <= 0) { continue; } apply_update_internal(dbnt, belowtype, childcnt, cu.optype, true); } }
/* * Can try to allocate a dbn with preferrene, this is suitable for * inplace writes of L0 data. */ public int allocate_dbn(BLK_TYPE btype, int preferreddbn) { /* * First see if it is in the list. * Now search the list. */ /* * lock (GLOBALQ.m_deletelog) * { * int count = (GLOBALQ.m_deletelog.Count > 16) ? 16 : GLOBALQ.m_deletelog.Count; * * for (int i = 0; i < count; i++) * { * int dbn = (int)(GLOBALQ.m_deletelog.ElementAt(0)); * GLOBALQ.m_deletelog.RemoveAt(0); * * if (dbn == preferreddbn) * { * return preferreddbn; * } * else * { * m_dbnbitmap.free_bit(dbn); * } * } * } * * if (m_dbnbitmap.try_alloc_bit(preferreddbn) == true) * { * return preferreddbn; * } */ /* * At this point, we have done the delete queue, and picked up the cost. * And now we have to allocate some random one and return. */ return(m_dbnbitmap.allocate_bit()); }