Exemple #1
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);
        }
Exemple #2
0
        /*
         * For a given rbn, it will load the 4k page into memory and return.
         * Also updates the queue to indicate the same.
         */
        private void load_wrbufx(int rbn)
        {
            if (GLOBALQ.WRObj[rbn].incoretbuf != null)
            {
                cachehits++;
            }
            else
            {
                WRBuf tbuf = allocate(rbn);

                mfile1.Seek((long)rbn * 4096, SeekOrigin.Begin);
                mfile1.Read(tmpiodata, 0, 4096);
                CONFIG.Decrypt_Read_WRBuf(tmpiodata, tbuf.data);

                GLOBALQ.WRObj[rbn].incoretbuf = tbuf;
                refcache[cachesize++]         = tbuf;
            }

            DoSnapshotWork(rbn);

            /* After the load, see if we have to clean up */
            if (cachesize > 15 * 1024)
            {
                internal_sync_and_flush_cache_advanced();
            }
        }
        public RedFSPersistantStorage(string name, string clog)
        {
            dfile = new FileStream(CONFIG.GetBasePath() + name,
                                   FileMode.OpenOrCreate, FileAccess.ReadWrite);

            clogfile = new FileStream(CONFIG.GetBasePath() + clog,
                                      FileMode.OpenOrCreate, FileAccess.ReadWrite);

            initialized = true;
        }
Exemple #4
0
        private void sync_buf(int rbn)
        {
            long offset = 4096 * (long)(rbn);

            CONFIG.Encrypt_Data_ForWrite(tmpiodata, GLOBALQ.WRObj[rbn].incoretbuf.data);
            mfile1.Seek(offset, SeekOrigin.Begin);
            mfile1.Write(tmpiodata, 0, 4096);

            GLOBALQ.WRObj[rbn].incoretbuf.is_dirty = false;
        }
        public void swap_clog()
        {
            flush_clog();
            lock (fpcache_buf)
            {
                clogfile.Flush();
                clogfile.Close();

                File.Move(CONFIG.GetBasePath() + "clog", CONFIG.GetBasePath() + "clog1");
                clogfile = new FileStream(CONFIG.GetBasePath() + "clog",
                                          FileMode.OpenOrCreate, FileAccess.ReadWrite);
            }
        }
        //private int start_dbn_bulk;

        public Map256M(string name)
        {
            mfile = new FileStream(CONFIG.GetBasePath() + name,
                                   FileMode.OpenOrCreate, FileAccess.ReadWrite);
            xfile = new FileStream(CONFIG.GetBasePath() + name + ".x",
                                   FileMode.OpenOrCreate, FileAccess.ReadWrite);
            initialized = true;

            byte[] buf = new byte[4];
            xfile.Read(buf, 0, 4);
            USED_BLK_COUNT = OPS.get_dbn(buf, 0);
            DEFS.DEBUGYELLOW("REF", "Found used block count = " + USED_BLK_COUNT);
        }
        public static void INIT_LOGGING()
        {
            string t = get_time_formatted();

            DEFS.DEBUG("IFSD", "Setting INIT_LOGGING()" + t);
            if (log == null)
            {
                string fname = CONFIG.GetBasePath() + "log_" + t + ".txt";
                Console.WriteLine("Setting INIT_LOGGING()" + fname);
                log = new StreamWriter(fname);
                DEFS.DEBUG("IFSD", "Setting INIT_LOGGING()" + t);
            }

            DEFS.DEBUG("IFSD", "Done INIT_LOGGING()");
        }
Exemple #8
0
        void worker_DoWork(object sender, DoWorkEventArgs e)
        {
            int total_blks    = f1blks + f2blks + f3blks;
            int complete_blks = 0;

            byte[] buffer = new byte[4096];
            byte[] encbuf = new byte[4096];

            FileStream f1 = new FileStream(selectedfolder + "\\disk2", FileMode.OpenOrCreate);

            for (int i = 0; i < f1blks; i++)
            {
                f1.Write(buffer, 0, 4096);
                complete_blks++;
                worker.ReportProgress(100 * complete_blks / total_blks, "Creating disk : " + selectedfolder + "\\disk2");
            }

            FileStream f2 = new FileStream(selectedfolder + "\\RFI2.dat", FileMode.OpenOrCreate);

            CONFIG.GenerateXORBuf(selectedfolder, encbuf);
            for (int i = 0; i < f2blks; i++)
            {
                f2.Write(encbuf, 0, 4096);
                complete_blks++;
                worker.ReportProgress(100 * complete_blks / total_blks, "Creating refcount file : " + selectedfolder + "\\RFI2.dat");
            }

            FileStream f3 = new FileStream(selectedfolder + "\\allocationmap", FileMode.OpenOrCreate);

            for (int i = 0; i < f3blks; i++)
            {
                f3.Write(buffer, 0, 4096);
                complete_blks++;
                worker.ReportProgress(100 * complete_blks / total_blks, "Creating AMap : " + selectedfolder + "\\allocationmap");
            }
            f1.Flush();
            f2.Flush();
            f3.Flush();
            f1.Close();
            f2.Close();
            f3.Close();

            CONFIG.CreateConfigInformation2(selectedfolder);
            worker.ReportProgress(-1, "finish!!");
        }
Exemple #9
0
        private void button3_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog folderBrowserDialog1 = new FolderBrowserDialog();

            if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
            {
                string path = folderBrowserDialog1.SelectedPath;
                if (CONFIG.CheckIfValidFolder(path) == CONFIGERROR.OKAY)
                {
                    MessageBox.Show("This folder already contains a valid virtual disk!", "Error", MessageBoxButtons.OK);
                }
                else
                {
                    selectedfolder = folderBrowserDialog1.SelectedPath;
                    textBox1.Text  = selectedfolder;
                }
            }
        }
Exemple #10
0
        public WRLoader()
        {
            m_creation_time = DateTime.Now.ToUniversalTime().Ticks;

            for (int i = 0; i < iStack.Length; i++)
            {
                iStack[i] = new WRBuf(0);
            }
            iStackTop = iStack.Length - 1;

            for (int i = 0; i < GLOBALQ.WRObj.Length; i++)
            {
                GLOBALQ.WRObj[i] = new WRContainer();
            }

            mfile1 = new FileStream(CONFIG.GetRefCntFilePath(), FileMode.OpenOrCreate, FileAccess.ReadWrite);
            tfile0 = new FileStream(CONFIG.GetTFilePath(), FileMode.OpenOrCreate, FileAccess.ReadWrite);
            dfile1 = new FileStream(CONFIG.GetDLogFilePath(), FileMode.OpenOrCreate, FileAccess.ReadWrite);
        }
Exemple #11
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);
            }
        }
        private void start_operation()
        {
            string input_clog       = CONFIG.GetBasePath() + "clog1";
            string clog_inofbn      = CONFIG.GetBasePath() + "clog.inofbn";
            string clog_inofbnclean = CONFIG.GetBasePath() + "clog.inofbn.clean";
            string clog_dbn         = CONFIG.GetBasePath() + "clog.dbn";
            string clog_dbnclean    = CONFIG.GetBasePath() + "clog.dbn.clean";
            string clog_fporder     = CONFIG.GetBasePath() + "clog.fporder";

            string fpdb_input = CONFIG.GetBasePath() + "fpdb1";

            string fpdb_dbncleaned = CONFIG.GetBasePath() + "fpdb.dbn.clean";
            string fpdb_fporder    = CONFIG.GetBasePath() + "fpdb.fporder";

            string fpdb_temp = CONFIG.GetBasePath() + "fpdb.temp";

            string dedupeScript_a = CONFIG.GetBasePath() + "script.dedupeop.temp";
            string dedupeScript   = CONFIG.GetBasePath() + "script.dedupeop";

            REDDY.ptrRedFS.dedupe_swap_changelog();

            if (File.Exists(input_clog) == false)
            {
                DEFS.DEBUG("DE", "Input clog does not exist, so no dedupe op now!");
                return;
            }

            /*
             * Prepare the changelog.
             */
            print_file(RECORD_TYPE.FINGERPRINT_RECORD_CLOG, DEDUP_SORT_ORDER.DBN_BASED, input_clog, input_clog + ".txt");
            m_stage = DEDUP_ENGINE_STAGE.SORT_CLOG_INOFBN;
            sort_dedupe_file(RECORD_TYPE.FINGERPRINT_RECORD_CLOG, input_clog, clog_inofbn, DEDUP_SORT_ORDER.INO_FBN_BASED);
            ui.Update_DedupeUI(DEDUP_ENGINE_STAGE.SORT_CLOG_INOFBN, 100);

            print_file(RECORD_TYPE.FINGERPRINT_RECORD_CLOG, DEDUP_SORT_ORDER.INO_FBN_BASED, clog_inofbn, clog_inofbn + ".txt");
            m_stage = DEDUP_ENGINE_STAGE.CLEAN_CLOG_INOFBNSTALES;
            clean_clog_file_P1(clog_inofbn, clog_inofbnclean);
            ui.Update_DedupeUI(DEDUP_ENGINE_STAGE.CLEAN_CLOG_INOFBNSTALES, 100);

            print_file(RECORD_TYPE.FINGERPRINT_RECORD_CLOG, DEDUP_SORT_ORDER.INO_FBN_BASED, clog_inofbnclean, clog_inofbnclean + ".txt");
            m_stage = DEDUP_ENGINE_STAGE.SORT_CLOG_DBN;
            sort_dedupe_file(RECORD_TYPE.FINGERPRINT_RECORD_CLOG, clog_inofbnclean, clog_dbn, DEDUP_SORT_ORDER.DBN_BASED);
            ui.Update_DedupeUI(DEDUP_ENGINE_STAGE.SORT_CLOG_DBN, 100);

            //commenting this off for now.
            print_file(RECORD_TYPE.FINGERPRINT_RECORD_CLOG, DEDUP_SORT_ORDER.DBN_BASED, clog_dbn, clog_dbn + ".txt");
            m_stage = DEDUP_ENGINE_STAGE.CLEAN_CLOG_DBNSTALES;
            clean_clog_file_P2(clog_dbn, clog_dbnclean);
            ui.Update_DedupeUI(DEDUP_ENGINE_STAGE.CLEAN_CLOG_DBNSTALES, 100);

            print_file(RECORD_TYPE.FINGERPRINT_RECORD_CLOG, DEDUP_SORT_ORDER.DBN_BASED, clog_dbnclean, clog_dbnclean + ".txt");
            m_stage = DEDUP_ENGINE_STAGE.SORT_CLOG_FPORDER;
            sort_dedupe_file(RECORD_TYPE.FINGERPRINT_RECORD_CLOG, clog_dbnclean, clog_fporder, DEDUP_SORT_ORDER.FINGERPRINT_BASED);
            print_file(RECORD_TYPE.FINGERPRINT_RECORD_CLOG, DEDUP_SORT_ORDER.FINGERPRINT_BASED, clog_fporder, clog_fporder + ".txt");
            ui.Update_DedupeUI(DEDUP_ENGINE_STAGE.SORT_CLOG_FPORDER, 100);

            remove_file(input_clog);
            remove_file(clog_inofbn);
            remove_file(clog_inofbnclean);
            remove_file(clog_dbn);
            remove_file(clog_dbnclean);

            /*
             * Prepare the fpdb. we have 'clog_fporder' from above steps
             * We must have a delete log that should be applied to clean the FPDB,
             */
            if (File.Exists(fpdb_input))
            {
                print_file(RECORD_TYPE.FINGERPRINT_RECORD_FPDB, DEDUP_SORT_ORDER.DBN_BASED, fpdb_input, fpdb_input + ".old.txt");

                m_stage = DEDUP_ENGINE_STAGE.CLEAN_FPDB_DBNSTALES;
                clean_fpdb_P1(fpdb_input, fpdb_dbncleaned);
                remove_file(fpdb_input);
                ui.Update_DedupeUI(DEDUP_ENGINE_STAGE.CLEAN_FPDB_DBNSTALES, 100);
                print_file(RECORD_TYPE.FINGERPRINT_RECORD_FPDB, DEDUP_SORT_ORDER.DBN_BASED, fpdb_dbncleaned, fpdb_dbncleaned + ".txt");

                m_stage = DEDUP_ENGINE_STAGE.SORT_FPDB_FPORDER;
                sort_dedupe_file(RECORD_TYPE.FINGERPRINT_RECORD_FPDB, fpdb_dbncleaned, fpdb_fporder, DEDUP_SORT_ORDER.FINGERPRINT_BASED);
                remove_file(fpdb_dbncleaned);
                print_file(RECORD_TYPE.FINGERPRINT_RECORD_FPDB, DEDUP_SORT_ORDER.FINGERPRINT_BASED, fpdb_fporder, fpdb_fporder + ".txt");
                ui.Update_DedupeUI(DEDUP_ENGINE_STAGE.SORT_FPDB_FPORDER, 100);
            }

            /*
             * Do the dedupe operation. we have 'fpdb_fporder' from above steps.
             */
            m_stage = DEDUP_ENGINE_STAGE.GENERATE_DEDUPE_SCRIPT;
            GenDedupeScript(fpdb_fporder, clog_fporder, fpdb_temp, dedupeScript_a);
            print_file(RECORD_TYPE.FINGERPRINT_RECORD_MSG, DEDUP_SORT_ORDER.FINGERPRINT_BASED, dedupeScript_a, dedupeScript_a + ".txt");
            print_file(RECORD_TYPE.FINGERPRINT_RECORD_FPDB, DEDUP_SORT_ORDER.FINGERPRINT_BASED, fpdb_temp, fpdb_temp + ".txt");
            remove_file(fpdb_fporder);
            remove_file(clog_fporder);
            ui.Update_DedupeUI(DEDUP_ENGINE_STAGE.GENERATE_DEDUPE_SCRIPT, 100);

            /*
             * Create the new fpdb.
             */
            m_stage = DEDUP_ENGINE_STAGE.SORT_FPDBT_DBN;
            sort_dedupe_file(RECORD_TYPE.FINGERPRINT_RECORD_FPDB, fpdb_temp, fpdb_input, DEDUP_SORT_ORDER.DBN_BASED);
            print_file(RECORD_TYPE.FINGERPRINT_RECORD_FPDB, DEDUP_SORT_ORDER.DBN_BASED, fpdb_input, fpdb_input + ".txt");
            remove_file(fpdb_temp);
            ui.Update_DedupeUI(DEDUP_ENGINE_STAGE.SORT_FPDBT_DBN, 100);

            m_stage = DEDUP_ENGINE_STAGE.SORT_SCRIPT_INOFBN;
            sort_dedupe_file(RECORD_TYPE.FINGERPRINT_RECORD_MSG, dedupeScript_a, dedupeScript, DEDUP_SORT_ORDER.INO_FBN_BASED);
            print_file(RECORD_TYPE.FINGERPRINT_RECORD_MSG, DEDUP_SORT_ORDER.INO_FBN_BASED, dedupeScript, dedupeScript + ".txt");
            ui.Update_DedupeUI(DEDUP_ENGINE_STAGE.SORT_SCRIPT_INOFBN, 100);


            //rename the file and get over with it.
            m_stage = DEDUP_ENGINE_STAGE.DEDUPE_MESSAGES;
            ACTUAL_DEDUPE(dedupeScript);
            remove_file(dedupeScript);
            remove_file(dedupeScript_a);
            ui.Update_DedupeUI(DEDUP_ENGINE_STAGE.DEDUPE_MESSAGES, 100);
            m_stage = DEDUP_ENGINE_STAGE.DEDUPE_DONE;

            System.Threading.Thread.Sleep(2000);
            ui.Update_DedupeUI(DEDUP_ENGINE_STAGE.DEDUPE_DONE, 100);
        }
Exemple #13
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);
        }