Skip to content

Commit

Permalink
Merge pull request mozilla#7 from MozCloudStorage/cloudxpcom
Browse files Browse the repository at this point in the history
Get attribute from cloud storage
  • Loading branch information
edenchuang committed Jun 3, 2015
2 parents 9884ed3 + c31502d commit 70c8c62
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 36 deletions.
1 change: 1 addition & 0 deletions dom/cloudstorage/moz.build
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ LOCAL_INCLUDES += [
'/dom/base',
'/dom/ipc',
'/dom/system/gonk/cloudstorage',
'/dom/system/gonk/cloudstorage/fuse',
]

#MOCHITEST_MANIFESTS += [
Expand Down
26 changes: 25 additions & 1 deletion dom/system/gonk/cloudstorage/CloudStorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ CloudStorage::CloudStorage(const nsCString& aCloudStorageName)
mRequestData(),
mResponseData(),
mNodeHashTable(),
mPathHashTable()
mPathHashTable(),
mAttrHashTable()
{
mMountPoint.Append("/data/cloud");
if ( -1 == mkdir(mMountPoint.get(), S_IRWXU|S_IRWXG)) {
Expand Down Expand Up @@ -170,6 +171,29 @@ CloudStorage::RemoveNIdByPath(nsCString aKey)
mPathHashTable.Remove(aKey);
}

FuseAttr
CloudStorage::GetAttrByPath(nsCString aPath)
{
FuseAttr res;
if (!mAttrHashTable.Get(aPath, &res)) {
LOG("No attr for path %s", aPath.get());
res.size = 0;
}
return res;
}

void
CloudStorage::SetAttrByPath(nsCString aPath, FuseAttr attr)
{
mAttrHashTable.Put(aPath, attr);
}

void
CloudStorage::RemoveAttrByPath(nsCString aPath)
{
mAttrHashTable.Remove(aPath);
}


} // end namespace cloudstorage
} // end namespace system
Expand Down
6 changes: 6 additions & 0 deletions dom/system/gonk/cloudstorage/CloudStorage.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "nsCOMPtr.h"
#include "nsRefPtr.h"
#include "nsDataHashtable.h"
#include "fuse.h"

namespace mozilla {
namespace system {
Expand Down Expand Up @@ -103,6 +104,10 @@ class CloudStorage final
void PutNIdByPath(nsCString aKey, uint64_t aNId);
void RemoveNIdByPath(nsCString aKey);

FuseAttr GetAttrByPath(nsCString aPath);
void SetAttrByPath(nsCString aPath, FuseAttr aAttr);
void RemoveAttrByPath(nsCString aPath);

void StartStorage();
void StopStorage();

Expand All @@ -116,6 +121,7 @@ class CloudStorage final
CloudStorageResponseData mResponseData;
nsDataHashtable<nsUint64HashKey, nsCString> mNodeHashTable;
nsDataHashtable<nsCStringHashKey, uint64_t> mPathHashTable;
nsDataHashtable<nsCStringHashKey, FuseAttr> mAttrHashTable;
};

} // end namespace cloudstorage
Expand Down
60 changes: 31 additions & 29 deletions dom/system/gonk/cloudstorage/CloudStorageRequestHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ class CloudStorageRequestRunnable : public nsRunnable
}

nsresult Run()
{

{
LOG("call do_CreateInstance for cloudstorageinterface");
nsresult rv;
nsCOMPtr<nsICloudStorageInterface> csi = do_CreateInstance(
Expand Down Expand Up @@ -320,17 +319,14 @@ CloudStorageRequestHandler::HandleRequest(const FuseInHeader *hdr, const void *d
void
CloudStorageRequestHandler::SendRequestToMainThread()
{
/*
mCloudStorage->SetWaitForRequest(true);
nsresult rv = NS_DispatchToMainThread(new CloudStorageRequestRunnable(mCloudStorage));
if (NS_FAILED(rv)) {
LOG("dispatch to main thread fail %x", rv);
}
LOG("return value: %x", rv);
while (mCloudStorage->IsWaitForRequest() && mCloudStorage->State() == CloudStorage::STATE_RUNNING) {
sleep(1);
usleep(10);
}
*/
}

uint64_t
Expand Down Expand Up @@ -368,8 +364,22 @@ CloudStorageRequestHandler::HandleLookup(const FuseInHeader *hdr, const char* na
}

FuseEntryOut out;
/*
CloudStorageTester tester;
out.attr = tester.GetAttrByPath(childpath, hdr->nodeid);
tester.GetAttrByPath(childpath, hdr->nodeid);
*/
out.attr.ino = hdr->nodeid;
out.attr = mCloudStorage->GetAttrByPath(childpath);
if (out.attr.size == 0) {
LOG("No Attr for path, send request to main thread");
CloudStorageRequestData reqData;
reqData.RequestType = (uint32_t) FUSE_GETATTR;
reqData.Path = childpath;
mCloudStorage->SetRequestData(reqData);
SendRequestToMainThread();
out.attr = mCloudStorage->GetAttrByPath(childpath);
}

out.attr_valid = 10;
out.entry_valid = 10;
out.nodeid = childnid;
Expand Down Expand Up @@ -413,30 +423,22 @@ CloudStorageRequestHandler::HandleGetAttr(const FuseInHeader *hdr, const FuseGet

FuseAttrOut attrOut;

/*
CloudStorageTester tester;
attrOut.attr = tester.GetAttrByPath(path, hdr->nodeid);

CloudStorageRequestData reqData;
reqData.Path = path;
mCloudStorage->SetRequestData(reqData);
mCloudStorage->SetWaitForRequest(true);
nsresult rv = NS_DispatchToMainThread(new CloudStorageRequestRunnable(mCloudStorage));
if (NS_FAILED(rv)) {
LOG("dispatch to main thread fail %x", rv);
}
while (mCloudStorage->IsWaitForRequest() && mCloudStorage->State() == CloudStorage::STATE_RUNNING) {
sleep(1);
}

attrOut.attr.size = mCloudStorage->ResponseData().FileSize;
attrOut.attr.atime = mCloudStorage->ResponseData().MTime;
attrOut.attr.mtime = mCloudStorage->ResponseData().MTime;
attrOut.attr.ctime = mCloudStorage->ResponseData().CTime;
attrOut.attr.atimensec = mCloudStorage->ResponseData().MTime;
attrOut.attr.mtimensec = mCloudStorage->ResponseData().MTime;
attrOut.attr.ctimensec = mCloudStorage->ResponseData().CTime;

tester.GetAttrByPath(path, hdr->nodeid);
*/
attrOut.attr.ino = hdr->nodeid;
attrOut.attr = mCloudStorage->GetAttrByPath(path);
LOG("attr.size: %llu", attrOut.attr.size);
if (attrOut.attr.size == 0) {
LOG("No attr for path, send request to main thread");
CloudStorageRequestData reqData;
reqData.RequestType = (uint32_t) FUSE_GETATTR;
reqData.Path = path;
mCloudStorage->SetRequestData(reqData);
SendRequestToMainThread();
attrOut.attr = mCloudStorage->GetAttrByPath(path);
}
attrOut.attr_valid = 10;

if (mCloudStorage->State() == CloudStorage::STATE_RUNNING) {
Expand Down
13 changes: 13 additions & 0 deletions dom/system/gonk/cloudstorage/CloudStorageTester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,19 @@ CloudStorageTester::GetAttrByPath(const nsCString& aPath, const uint64_t aNodeId
attr.nlink = s.st_nlink;
attr.uid = 0;
attr.gid = 1015;
LOG("size: %llu", attr.size);
LOG("blocks: %llu", attr.blocks);
LOG("blocksize: %u", attr.blksize);
LOG("atime: %llu", attr.atime);
LOG("mtime: %llu", attr.mtime);
LOG("ctime: %llu", attr.ctime);
LOG("atimensec: %u", attr.atimensec);
LOG("mtimensec: %u", attr.mtimensec);
LOG("ctimensec: %u", attr.ctimensec);
LOG("mode: %x", attr.mode);
LOG("nlinks: %u", attr.nlink);
LOG("rdev: %u", attr.rdev);
LOG("padding: %u", attr.padding);
return attr;
}

Expand Down
34 changes: 28 additions & 6 deletions dom/system/gonk/cloudstorage/nsCloudStorageGeckoInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include "CloudStorageLog.h"
#include "CloudStorageManager.h"
#include "CloudStorage.h"
#include "fuse.h"
#include <time.h>

using namespace mozilla::system::cloudstorage;
using namespace mozilla;
Expand Down Expand Up @@ -39,12 +41,32 @@ nsCloudStorageGeckoInterface::SetFileMeta(const nsACString_internal& aCloudName,
RefPtr<CloudStorage> cloudStorage = CloudStorageManager::FindCloudStorageByName(cloudName);
LOG("in CloudStorageGeckoInterface::SetFileMeta");
LOG("file type: %s, size: %llu, modified time: %llu, created time: %llu", aIsDir?"Directory":"File", aSize, aMTime, aCTime);
CloudStorageResponseData resData;
resData.IsDir = aIsDir;
resData.FileSize = aSize;
resData.MTime = aMTime;
resData.CTime = aCTime;
cloudStorage->SetResponseData(resData);

FuseAttr attr;
if (aIsDir) {
attr.size = 4096;
attr.blocks = 8;
attr.blksize = 512;
attr.mode = 0x41ff;
} else {
attr.size = aSize;
attr.blocks = aSize/512;
attr.blksize = 512;
attr.mode = 0x81fd;
}
if (aMTime != 0 && aCTime != 0) {
attr.atime = aMTime/1000;
attr.mtime = aMTime/1000;
attr.ctime = aCTime/1000;
} else {
attr.atime = time(NULL);
attr.mtime = attr.atime;
attr.ctime = attr.ctime;
}
attr.uid = 0;
attr.gid = 1015;

cloudStorage->SetAttrByPath(path, attr);
cloudStorage->SetWaitForRequest(false);
return NS_OK;
}
Expand Down
1 change: 1 addition & 0 deletions dom/system/gonk/moz.build
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ LOCAL_INCLUDES += [
'/dom/bluetooth',
'/dom/geolocation',
'/dom/system/gonk/cloudstorage',
'/dom/system/gonk/cloudstorage/fuse',
'/dom/wifi',
]

Expand Down

0 comments on commit 70c8c62

Please sign in to comment.