Example #1
0
        public void sync2()
        {
            UpdateReqI r = new UpdateReqI();

            r.optype = REFCNT_OP.DO_SYNC;
            GLOBALQ.m_reqi_queue.Add(r);
        }
Example #2
0
        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);
        }
Example #3
0
        public void snapshot_scanner_dowork(int rbn, bool takesnap)
        {
            UpdateReqI r = new UpdateReqI();

            r.optype = (takesnap)? REFCNT_OP.TAKE_DISK_SNAPSHOT : REFCNT_OP.UNDO_DISK_SNAPSHOT;
            r.tfbn   = rbn;
            GLOBALQ.m_reqi_queue.Add(r);
        }
Example #4
0
        public void sync_blocking()
        {
            UpdateReqI r = new UpdateReqI();

            r.optype = REFCNT_OP.DO_SYNC;
            GLOBALQ.m_reqi_queue.Add(r);
            while (r.processed == false)
            {
                Thread.Sleep(100);
            }
        }
Example #5
0
        public void shut_down()
        {
            DEFS.DEBUG("SHUTDOWN", "Calling WRLoader() shut down");
            UpdateReqI r = new UpdateReqI();

            r.optype = REFCNT_OP.SHUT_DOWN;
            GLOBALQ.m_reqi_queue.Add(r);
            while (r.processed == false)
            {
                Thread.Sleep(100);
            }
            DEFS.DEBUG("SHUTDOWN", "Finishing WRLoader() shut down");
        }
Example #6
0
        public void get_refcount(int dbn, ref int refcnt, ref int childcnt)
        {
            UpdateReqI r = new UpdateReqI();

            r.optype = REFCNT_OP.GET_REFANDCHD_INFO;
            r.dbn    = dbn;
            GLOBALQ.m_reqi_queue.Add(r);

            int rbn = REFDEF.dbn_to_rbn(dbn);

            while (r.processed == false)
            {
                //Console.WriteLine("Waiting for refcount to turn up : " + dbn + "," + GLOBALQ.m_reqi_queue.Count);
                Thread.Sleep(10);
            }
            refcnt   = GLOBALQ.WRObj[rbn].incoretbuf.get_refcount(dbn);
            childcnt = GLOBALQ.WRObj[rbn].incoretbuf.get_childcount(dbn);
        }
Example #7
0
        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);
            }
        }
Example #8
0
        public void mod_refcount(int fsid, int dbn, REFCNT_OP optype, Red_Buffer wb, bool isinodefilel0)
        {
            DEFS.ASSERT(optype == REFCNT_OP.INCREMENT_REFCOUNT || /*optype == REFCNT_OP.DECREMENT_REFCOUNT ||*/
                        optype == REFCNT_OP.TOUCH_REFCOUNT ||     /*optype == REFCNT_OP.DO_LOAD || */
                        optype == REFCNT_OP.INCREMENT_REFCOUNT_ALLOC ||
                        optype == REFCNT_OP.DECREMENT_REFCOUNT_ONDEALLOC, "Wrong param in mod_refcount");

            DEFS.ASSERT(isinodefilel0 || (wb == null || wb.get_level() > 0), "wrong type to mod_refcount " + isinodefilel0 + (wb == null));

            UpdateReqI r = new UpdateReqI();

            r.optype = optype;
            r.dbn    = dbn;
            r.fsid   = fsid;

            switch (optype)
            {
            case REFCNT_OP.INCREMENT_REFCOUNT:
            case REFCNT_OP.INCREMENT_REFCOUNT_ALLOC:
                r.value = 1;
                break;

            //case REFCNT_OP.DECREMENT_REFCOUNT:
            case REFCNT_OP.DECREMENT_REFCOUNT_ONDEALLOC:
                r.value = -1;
                break;

            case REFCNT_OP.TOUCH_REFCOUNT:
                //case REFCNT_OP.DO_LOAD:
                r.value = 0;
                break;
            }

            r.blktype = (wb != null) ? ((isinodefilel0) ? BLK_TYPE.PUBLIC_INODE_FILE_L0 : wb.get_blk_type()) :
                        ((optype == REFCNT_OP.INCREMENT_REFCOUNT_ALLOC || optype == REFCNT_OP.DECREMENT_REFCOUNT_ONDEALLOC)?
                         BLK_TYPE.IGNORE : BLK_TYPE.REGULAR_FILE_L0);

            if (wb != null && (wb.get_level() > 0 || BLK_TYPE.PUBLIC_INODE_FILE_L0 == r.blktype))
            {
                lock (tfile0)
                {
                    CONFIG.Encrypt_Data_ForWrite(tmpiodatatfileW, wb.buf_to_data());
                    tfile0.Seek((long)tfilefbn * 4096, SeekOrigin.Begin);
                    tfile0.Write(tmpiodatatfileW, 0, 4096);
                    //DEFS.DEBUG("ENCY", "Wrote : " + OPS.ChecksumPageWRLoader(wb.buf_to_data()));
                    r.tfbn = tfilefbn;
                    tfilefbn++;
                }
            }
            else
            {
                r.tfbn = -1;
            }

            if (optype != REFCNT_OP.INCREMENT_REFCOUNT_ALLOC && optype != REFCNT_OP.DECREMENT_REFCOUNT &&
                optype != REFCNT_OP.DECREMENT_REFCOUNT_ONDEALLOC && optype != REFCNT_OP.TOUCH_REFCOUNT)
            {
                DEFS.DEBUG("REFCNT", "Queued update for " + r.blktype + ", dbn = " +
                           r.dbn + ", and operation = " + r.optype + ", transaction offset : " + r.tfbn);
            }

            GLOBALQ.m_reqi_queue.Add(r);
        }
Example #9
0
        /*
         * Will block on GLOBALQ.m_reqi_queue and take it to
         * its logical conclusion.
         */
        public void tServiceThread()
        {
            //long protected_blkdiff_counter = 0;
            long[] protected_blkdiff_counter = new long[1024];

            while (true)
            {
                UpdateReqI cu = (UpdateReqI)GLOBALQ.m_reqi_queue.Take();

                if (cu.optype == REFCNT_OP.SHUT_DOWN)
                {
                    internal_sync_and_flush_cache_advanced();
                    DEFS.ASSERT(GLOBALQ.m_reqi_queue.Count == 0, "There cannot be any pending updates when shutting down");
                    DEFS.DEBUGYELLOW("REF", "Bailing out now!!");
                    //dont take a lock here.

                    for (int i = 0; i < 1024; i++)
                    {
                        if (REDDY.FSIDList[i] == null || protected_blkdiff_counter[i] == 0)
                        {
                            continue;
                        }

                        REDDY.FSIDList[i].diff_upadate_logical_data(protected_blkdiff_counter[i]);
                        REDDY.FSIDList[i].set_dirty(true);
                        protected_blkdiff_counter[i] = 0;
                    }

                    cu.processed  = true;
                    m_initialized = false;
                    break;
                }

                if (cu.optype == REFCNT_OP.DO_SYNC)
                {
                    internal_sync_and_flush_cache_advanced();

                    //dont take a lock here.
                    for (int i = 0; i < 1024; i++)
                    {
                        if (REDDY.FSIDList[i] == null || protected_blkdiff_counter[i] == 0)
                        {
                            continue;
                        }

                        REDDY.FSIDList[i].diff_upadate_logical_data(protected_blkdiff_counter[i]);
                        REDDY.FSIDList[i].set_dirty(true);
                        protected_blkdiff_counter[i] = 0;
                    }
                    cu.processed = true;
                    tfile0.Flush();
                    mfile1.Flush();
                    dfile1.Flush();
                    continue;
                }

                if (cu.optype == REFCNT_OP.TAKE_DISK_SNAPSHOT ||
                    cu.optype == REFCNT_OP.UNDO_DISK_SNAPSHOT)
                {
                    int rbn_update = cu.tfbn; //overloaded since its just file offset.
                    load_wrbufx(rbn_update);  //will dowork
                    DEFS.ASSERT(cu.dbn == 0, "This should not be set");
                    DEFS.ASSERT(cu.optype == GLOBALQ.disk_snapshot_optype, "this must also match");
                    //DoSnapshotWork(rbn_update);
                    counter++;
                    total_ops++;
                    printspeed();
                    continue;
                }

                if (cu.dbn != 0)
                {
                    if (cu.optype == REFCNT_OP.DECREMENT_REFCOUNT_ONDEALLOC)
                    {
                        protected_blkdiff_counter[cu.fsid] -= 4096;
                    }
                    else if (cu.optype == REFCNT_OP.INCREMENT_REFCOUNT_ALLOC)
                    {
                        protected_blkdiff_counter[cu.fsid] += 4096;
                    }
                    //all other ops you can ignore.
                }

                int rbn = REFDEF.dbn_to_rbn(cu.dbn);
                total_ops++;
                counter++;

                /*
                 * Now if this has a child update pending, then we must clean it up.
                 * For each entry, i.e dbn, load the upto 1024, into memory and update
                 * the refcount. Essentially when we access this buffer - it must not
                 * have any pending update to itself or its children.
                 *
                 * How the children are updated depends on the blk_type, thats why so many
                 * cases.
                 */
                load_wrbufx(rbn);

                if (cu.optype == REFCNT_OP.GET_REFANDCHD_INFO)
                {
                    cu.processed = true;
                    continue;
                }

                int childcnt = GLOBALQ.WRObj[rbn].incoretbuf.get_childcount(cu.dbn);

                if (childcnt > 0)
                {
                    DEFS.DEBUG("CNTr", "Encountered child update for " + cu.dbn + " = " +
                               GLOBALQ.WRObj[rbn].incoretbuf.get_refcount(cu.dbn) + "," + childcnt);

                    if (cu.blktype == BLK_TYPE.REGULAR_FILE_L0)// || cu.blktype == BLK_TYPE.DIRFILE_L0)
                    {
                        /* Normal handling*/
                        //DEFS.ASSERT(cu.blktype == GLOBALQ.WRObj[rbn].incoretbuf.get_blk_type(cu.dbn), "Block mismatch");
                        DEFS.ASSERT(cu.tfbn == -1, "tfbn cannot be set for a level 0 block generally");
                        DEFS.ASSERT(false, "How can there be a childcnt update for a level zero block?");
                    }
                    else if (cu.blktype == BLK_TYPE.REGULAR_FILE_L1 || cu.blktype == BLK_TYPE.REGULAR_FILE_L2) /* ||
                                                                                                                * cu.blktype == BLK_TYPE.DIRFILE_L1 || cu.blktype == BLK_TYPE.DIRFILE_L2 ||
                                                                                                                * cu.blktype == BLK_TYPE.PUBLIC_INODE_FILE_L2 || cu.blktype == BLK_TYPE.PUBLIC_INODE_FILE_L1)*/
                    {
                        //DEFS.ASSERT(false, "Not yet implimented chdcnt in wrloader : " + REFDEF.get_string_rep(cu));
                        DEFS.ASSERT(cu.tfbn != -1, "Tfbn should've been set here.");
                        do_regular_dirORfile_work(cu, childcnt);
                        GLOBALQ.WRObj[rbn].incoretbuf.set_childcount(cu.dbn, 0);
                    }
                    else if (cu.blktype == BLK_TYPE.PUBLIC_INODE_FILE_L0)
                    {
                        DEFS.DEBUGCLR("------", "Do ino-L0 update work," + cu.optype + " , chdcnt = " + childcnt +
                                      " curr_refcnt = " + GLOBALQ.WRObj[rbn].incoretbuf.get_refcount(cu.dbn));
                        do_inode_refupdate_work(cu, childcnt);
                        GLOBALQ.WRObj[rbn].incoretbuf.set_childcount(cu.dbn, 0);
                    }
                    else
                    {
                        DEFS.ASSERT(false, "passed type = " + cu.blktype + "dbn = " + cu.dbn + " chdcnt = " + childcnt);
                    }
                }

                if (cu.optype != REFCNT_OP.TOUCH_REFCOUNT)
                {
                    /*
                     * Now that pending updates are propogated ,apply the queued update to this refcount.
                     * If it becomes free, notify that.
                     */
                    load_wrbufx(rbn);

                    apply_update_internal(cu.dbn, cu.blktype, cu.value, cu.optype, (cu.optype == REFCNT_OP.INCREMENT_REFCOUNT));

                    checkset_if_blockfree(cu.dbn, childcnt);
                }

                /* After the load, see if we have to clean up */
                if (cachesize > 15 * 1024)
                {
                    internal_sync_and_flush_cache_advanced();
                }
                printspeed();
            }

            tfile0.Flush();
            tfile0.Close();
            dfile1.Flush();
            dfile1.Close();
            mfile1.Flush();
            mfile1.Close();
        }
Example #10
0
 //public static Int16 parse_flag(byte[] data, int idx) { return 0; }
 //public static void set_flag(byte[] data, int idx, Int16 flag) { }
 public static string get_string_rep(UpdateReqI cu)
 {
     return("dbn, blk, op, value, tfbn = " + cu.dbn + "," + cu.blktype +
            "," + cu.optype + "," + cu.value + "," + cu.tfbn);
 }