Пример #1
0
        public static bool Checkin_Wip(RedFS_Inode inowip, RedFS_Inode mywip, int m_ino)
        {
            DEFS.ASSERT(m_ino == mywip.get_ino(), "Inode numbers dont match, can lead to corruption " + m_ino + "," + mywip.get_ino());
            long fileoffset = m_ino * 128;

            lock (inowip)
            {
                REDDY.ptrRedFS.redfs_write(inowip, fileoffset, mywip.data, 0, 128);
                DEFS.DEBUG("OPS", "CheckIn wip " + mywip.get_ino() + " size = " + mywip.get_filesize());
                inowip.is_dirty = true;
            }
            DEFS.DEBUG("CI_WIP", mywip.get_string_rep2());
            return(true);
        }
        private void CheckSumBuf(RedFS_Inode wip, int fbn, int dbn, byte[] buffer, int offset)
        {
            lock (fpcache_buf)
            {
                if (fpcache_cnt == 1024)
                {
                    fpcache_cnt = 0;
                    clogfile.Write(fpcache_buf, 0, fpcache_buf.Length);
                    clogfile.Flush();
                }

                if (wip.get_wiptype() == WIP_TYPE.REGULAR_FILE)
                {
                    fingerprintCLOG fpt = (fingerprintCLOG)fptemp;

                    fpt.fsid  = wip.get_filefsid();
                    fpt.inode = wip.get_ino();
                    fpt.fbn   = fbn;
                    fpt.dbn   = dbn;
                    fpt.cnt   = (int)clogfile.Position;

                    byte[] hash = md5.ComputeHash(buffer, offset, 4096);
                    for (int i = 0; i < 16; i++)
                    {
                        fpt.fp[i] = hash[i];
                    }

                    fptemp.get_bytes(fpcache_buf, fpcache_cnt * fptemp.get_size());
                    fpcache_cnt++;
                }
            }
        }
        private void CheckSumBuf(RedFS_Inode wip, Red_Buffer wb)
        {
            lock (fpcache_buf)
            {
                if (fpcache_cnt == 1024)
                {
                    fpcache_cnt = 0;
                    clogfile.Write(fpcache_buf, 0, fpcache_buf.Length);
                    clogfile.Flush();
                }

                if (wb.get_level() == 0 && wip.get_wiptype() == WIP_TYPE.REGULAR_FILE)
                {
                    fingerprintCLOG fpt = (fingerprintCLOG)fptemp;

                    fpt.fsid  = wip.get_filefsid();
                    fpt.inode = wip.get_ino();
                    fpt.fbn   = (int)wb.get_start_fbn();
                    fpt.dbn   = wb.get_ondisk_dbn();
                    fpt.cnt   = (int)clogfile.Position;

                    byte[] hash = md5.ComputeHash(wb.buf_to_data());
                    for (int i = 0; i < 16; i++)
                    {
                        fpt.fp[i] = hash[i];
                    }

                    fptemp.get_bytes(fpcache_buf, fpcache_cnt * fptemp.get_size());
                    fpcache_cnt++;
                }
            }
        }
Пример #4
0
        /*
         * public static Red_Buffer get_buf2(string who, RedFS_Inode wip, int level, int some_fbn, bool isquery)
         * {
         *  DEFS.DEBUG("getbuf", "-> " + who + "," + wip.m_ino + "," + level + "," + some_fbn + "," + isquery);
         *  Red_Buffer retbuf = wip.FindOrInsertOrRemoveBuf(FIR_OPTYPE.FIND, level, some_fbn, null, null);
         *  if (!isquery)
         *  {
         *      DEFS.ASSERT(retbuf != null, "newer get_buf2 has failed");
         *  }
         *  return retbuf;
         * }
         */
        /*
         * This can never return null, the caller *must* know that this buffer
         * is incore before calling. Must be called with a lock held on wip. But in case
         * is query is set true, then the caller is not sure if the buf is incore, in that
         * case we can return null safely.
         */

        public static Red_Buffer get_buf3(string who, RedFS_Inode wip, int level, int some_fbn, bool isquery)
        {
            List <Red_Buffer> list = null;

            switch (level)
            {
            case 0:
                list = wip.L0list;
                break;

            case 1:
                list = wip.L1list;
                break;

            case 2:
                list = wip.L2list;
                break;
            }
            DEFS.ASSERT(list != null, "List cannot be null in get_buf()");

            int start_fbn = SomeFBNToStartFBN(level, some_fbn);

            //some optimization, 10-12 mbps more.
            if (level == 1)
            {
                if (wip._lasthitbuf != null && wip._lasthitbuf.get_start_fbn() == start_fbn)
                {
                    return(wip._lasthitbuf);
                }
            }

            for (int idx = 0; idx < (list.Count); idx++)
            //for (int idx = (list.Count - 1); idx >= 0; idx--)
            {
                int        idx2 = (level == 0) ? (list.Count - idx - 1) : idx;
                Red_Buffer wb   = (Red_Buffer)list.ElementAt(idx2);
                if (wb.get_start_fbn() == start_fbn)
                {
                    //if (wb.get_level() > 0 && list.Count > 2) //like splay tree.
                    //{
                    //    list.RemoveAt(idx2);
                    //    list.Insert(0, wb);
                    //}
                    if (level == 1)
                    {
                        wip._lasthitbuf = wb;             //good opti - gives 10-12mbps more.
                    }
                    return(wb);
                }
            }

            DEFS.ASSERT(isquery, "who = " + who + ", get_buf() failed " + wip.get_ino() + "," + level + "," + some_fbn);
            return(null);
        }
Пример #5
0
        public static void dump_inoL0_wips(byte[] buffer)
        {
            byte[]      buf = new byte[128];
            RedFS_Inode wip = new RedFS_Inode(WIP_TYPE.REGULAR_FILE, 0, 0);

            for (int i = 0; i < 32; i++)
            {
                for (int t = 0; t < 128; t++)
                {
                    buf[t] = buffer[i * 128 + t];
                }
                wip.parse_bytes(buf);
                if (wip.get_ino() != 0)
                {
                    DEFS.DEBUG("->", wip.get_string_rep2());
                }
            }
        }