private void MSG_AGGREGATE(fingerprintDMSG msg)
        {
            if (msg == null)
            {
                if (counter > 0)
                {
                    REDDY.ptrIFSDMux.DoDedupeBatch(msglist);
                }

                DEFS.DEBUGYELLOW("BATCH", "DoDedupeBatch, counter = " + counter);
                for (int i = 0; i < 1024; i++)
                {
                    msglist[i] = null;
                }
                counter = 0;
                top     = -1;
                return;
            }
            else if ((top == -1) || (msg.fsid == msglist[top].fsid && msg.inode == msglist[top].inode &&
                                     OPS.SomeFBNToStartFBN(1, msg.fbn) == OPS.SomeFBNToStartFBN(1, msglist[top].fbn)))
            {
                int idx = (int)(msg.fbn % 1024);
                DEFS.ASSERT(msglist[idx] == null, "This cannot be populated already");
                msglist[idx] = DUP(msg);
                top          = idx;
                counter++;
            }
            else
            {
                //send msg here.
                MSG_AGGREGATE(null);
                MSG_AGGREGATE(msg);
                return;
            }
        }
 public void shutdown()
 {
     if (iStackTop != iStack.Length - 1)
     {
         DEFS.DEBUGYELLOW("Y", "Appears that not all bufs are recovered : " + iStackTop);
     }
     //DEFS.ASSERT(iStackTop == iStack.Length - 1, "Appears that not all bufs are recovered : " + iStackTop);
 }
        public bool verify_inode_number()
        {
            bool retval = (get_int(WIDOffsets.wip_inoloc) == m_ino) ? true : false;

            if (get_int(WIDOffsets.wip_inoloc) != 0 && !retval)
            {
                DEFS.DEBUGYELLOW("ERROR", "Some error is detected!! retval = " + retval);
            }
            //DEFS.DEBUG("C", get_string_rep2());
            //DEFS.DEBUG("C", "in verify inode " + get_int(WIDOffsets.wip_inoloc) + "," + m_ino);
            return(retval);
        }
        //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);
        }
Exemple #5
0
        public static void save_task(string tname, BackupTask bt)
        {
            MemoryStream  ms            = new MemoryStream();
            XmlSerializer SerializerObj = new XmlSerializer(typeof(BackupTask));

            SerializerObj.Serialize(ms, bt);

            byte[] buf       = ms.ToArray();
            uint   writesize = 0;

            REDDY.ptrIFSDMux.CreateFile(2, "\\" + tname + "\\task.xml", FileAccess.ReadWrite,
                                        FileShare.ReadWrite, FileMode.OpenOrCreate, FileOptions.None, null);
            REDDY.ptrIFSDMux.WriteFile(2, "\\" + tname + "\\task.xml", buf, ref writesize, 0, null);
            REDDY.ptrIFSDMux.CloseFile(2, "\\" + tname + "\\task.xml", null);
            DEFS.DEBUGYELLOW("TK", "Wrote file size = " + buf.Length);
        }
Exemple #6
0
        /*
         * This file dups itself into another file, the old version is not deleted.
         * More like a new reincarnate without loosing old data. The responsibility
         * of updating path/name is left to CDirectory, as there are only incore data
         * from the POV of CFile.
         */
        public CFile dup_file(int newfsid, int inode, int pino, string newpath)
        {
            if (m_state == FILE_STATE.FILE_DELETED)
            {
                return(null);
            }
            open_file(false);

            /*
             * It is okay to not lock cfnew since nobody actually know that this is
             * on the system. As nobody else touch this, we can do without locks for the new file.
             */
            lock (this)
            {
                if (_mywip == null)
                {
                    DEFS.ASSERT(m_state == FILE_STATE.FILE_DELETED, "Should be marked deleted, or else some workflow issue");
                    return(null);
                }

                REDDY.ptrRedFS.sync(_mywip);
                REDDY.ptrRedFS.flush_cache(_mywip, true);

                //should we write the source inodefile to disk also?
                CFile cfnew = new CFile(newfsid, inode, pino, m_name, newpath);
                cfnew.open_file(true);

                REDDY.ptrRedFS.redfs_dup_file(_mywip, cfnew._mywip);

                cfnew.m_atime = m_atime;
                cfnew.m_ctime = m_ctime;
                cfnew.m_mtime = m_mtime;
                cfnew.m_size  = _mywip.get_filesize();
                cfnew.set_ibflag(_mywip.get_ibflag());
                cfnew.touch();

                //int numblocks = OPS.FSIZETONUMBLOCKS(m_clist[i].get_size());
                int numblocks = OPS.NUML0(m_size) + OPS.NUML1(m_size) + OPS.NUML2(m_size);
                REDDY.FSIDList[newfsid].diff_upadate_logical_data(numblocks * 4096); //not the correct figure per-se
                REDDY.FSIDList[newfsid].set_dirty(true);
                DEFS.DEBUGYELLOW("INCRCNT", "Grew fsid usage by  " + numblocks + " (file)");

                cfnew.sync();
                return(cfnew);
            }
        }
Exemple #7
0
        /*
         * this will periodically check if any dbns have become free and free
         * it in the bitmap appropriately.
         */
        private void tServiceThread()
        {
            while (m_shutdown == false)
            {
                for (int i = 0; i < 10; i++)
                {
                    if (m_shutdown)
                    {
                        m_dbnbitmap.sync();
                        return;
                    }
                    System.Threading.Thread.Sleep(1000);
                }

                lock (GLOBALQ.m_deletelog2)
                {
                    int count = GLOBALQ.m_deletelog2.Count;
                    try
                    {
                        for (int i = 0; i < count; i++)
                        {
                            int dbn = (int)(GLOBALQ.m_deletelog2.ElementAt(0));
                            GLOBALQ.m_deletelog2.RemoveAt(0);
                            m_dbnbitmap.free_bit(dbn);
                        }
                        DEFS.DEBUGCLR("FREE", "Deallocated " + count + " dbns in this iteration");
                    }
                    catch (Exception e)
                    {
                        DEFS.DEBUGYELLOW("EXEPTION", "Caught in dellog : cnt = " + count + " and size = " +
                                         GLOBALQ.m_deletelog2.Count + " e.msg = " + e.Message);
                    }
                }
                m_dbnbitmap.sync();
            }
        }
Exemple #8
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();
        }