提交 b0d7b906 编写于 作者: O openharmony_ci 提交者: Gitee

!105 [LTS-3.0]修复在NFS上执行一次程序后在服务端修改程序可能引起错误的BUG

Merge pull request !105 from Far/cherry-pick-1640053555
...@@ -321,7 +321,8 @@ static int vfs_nfs_stat_internal(struct nfsmount *nmp, struct nfsnode *nfs_node) ...@@ -321,7 +321,8 @@ static int vfs_nfs_stat_internal(struct nfsmount *nmp, struct nfsnode *nfs_node)
/* Extract time values as type time_t in units of seconds */ /* Extract time values as type time_t in units of seconds */
fxdr_nfsv3time(&attr_reply.attr.fa_mtime, &ts); fxdr_nfsv3time(&attr_reply.attr.fa_mtime, &ts);
nfs_node->n_mtime = ts.tv_sec; nfs_node->n_timestamp.tv_sec = ts.tv_sec;
nfs_node->n_timestamp.tv_nsec = ts.tv_nsec;
fxdr_nfsv3time(&attr_reply.attr.fa_atime, &ts); fxdr_nfsv3time(&attr_reply.attr.fa_atime, &ts);
nfs_node->n_atime = ts.tv_sec; nfs_node->n_atime = ts.tv_sec;
...@@ -910,12 +911,12 @@ int vfs_nfs_stat(struct Vnode *node, struct stat *buf) ...@@ -910,12 +911,12 @@ int vfs_nfs_stat(struct Vnode *node, struct stat *buf)
buf->st_size = (off_t)nfs_node->n_size; buf->st_size = (off_t)nfs_node->n_size;
buf->st_blksize = 0; buf->st_blksize = 0;
buf->st_blocks = 0; buf->st_blocks = 0;
buf->st_mtime = nfs_node->n_mtime; buf->st_mtime = nfs_node->n_timestamp.tv_sec;
buf->st_atime = nfs_node->n_atime; buf->st_atime = nfs_node->n_atime;
buf->st_ctime = nfs_node->n_ctime; buf->st_ctime = nfs_node->n_ctime;
/* Adapt to kstat member "long tv_sec" */ /* Adapt to kstat member "long tv_sec" */
buf->__st_mtim32.tv_sec = (long)nfs_node->n_mtime; buf->__st_mtim32.tv_sec = (long)nfs_node->n_timestamp.tv_sec;
buf->__st_atim32.tv_sec = (long)nfs_node->n_atime; buf->__st_atim32.tv_sec = (long)nfs_node->n_atime;
buf->__st_ctim32.tv_sec = (long)nfs_node->n_ctime; buf->__st_ctim32.tv_sec = (long)nfs_node->n_ctime;
...@@ -3071,6 +3072,61 @@ errout_with_mutex: ...@@ -3071,6 +3072,61 @@ errout_with_mutex:
return -error; return -error;
} }
static int nfs_check_timestamp(struct timespec *origin, struct timespec *new)
{
return (origin->tv_sec == new->tv_sec) && (origin->tv_nsec == new->tv_nsec);
}
static int vfs_nfs_open(struct file *filep)
{
int ret;
struct timespec ts;
struct rpc_call_fs attr_call;
struct rpc_reply_getattr attr_reply;
struct Vnode *node = filep->f_vnode;
struct nfsnode *nfs_node = NULL;
struct nfsmount *nmp = (struct nfsmount *)(node->originMount->data);
struct file_handle parent_fhandle = {0};
nfs_mux_take(nmp);
nfs_node = (struct nfsnode *)node->data;
attr_call.fs.fsroot.length = txdr_unsigned(nfs_node->n_fhsize);
memcpy_s(&(attr_call.fs.fsroot.handle), sizeof(nfsfh_t), &(nfs_node->n_fhandle), sizeof(nfsfh_t));
ret = nfs_request(nmp, NFSPROC_GETATTR, &attr_call,
sizeof(struct file_handle), &attr_reply,
sizeof(struct rpc_reply_getattr));
if (ret != OK)
{
if (ret == NFSERR_STALE)
{
/* If the file handle is stale, update it */
OsFileCacheRemove(&(node->mapping));
parent_fhandle.length = ((struct nfsnode *)node->parent->data)->n_fhsize;
memcpy_s(&(parent_fhandle.handle), parent_fhandle.length,
&(((struct nfsnode *)node->parent->data)->n_fhandle),
((struct nfsnode *)node->parent->data)->n_fhsize);
ret = nfs_fileupdate(nmp, nfs_node->n_name, &parent_fhandle, nfs_node);
}
nfs_mux_release(nmp);
return ret;
}
/* Extract time values as timestamp */
fxdr_nfsv3time(&attr_reply.attr.fa_mtime, &ts);
if (!nfs_check_timestamp(&(nfs_node->n_timestamp), &ts))
{
OsFileCacheRemove(&(node->mapping));
nfs_node->n_timestamp.tv_sec = ts.tv_sec;
nfs_node->n_timestamp.tv_nsec = ts.tv_nsec;
}
nfs_mux_release(nmp);
return OK;
}
struct MountOps nfs_mount_operations = struct MountOps nfs_mount_operations =
{ {
.Mount = vfs_nfs_mount, .Mount = vfs_nfs_mount,
...@@ -3100,6 +3156,7 @@ struct VnodeOps nfs_vops = ...@@ -3100,6 +3156,7 @@ struct VnodeOps nfs_vops =
struct file_operations_vfs nfs_fops = struct file_operations_vfs nfs_fops =
{ {
.open = vfs_nfs_open,
.seek = vfs_nfs_seek, .seek = vfs_nfs_seek,
.write = vfs_nfs_write, .write = vfs_nfs_write,
.read = vfs_nfs_read, .read = vfs_nfs_read,
......
...@@ -83,8 +83,8 @@ struct nfsnode ...@@ -83,8 +83,8 @@ struct nfsnode
uint8_t n_flags; /* Node flags */ uint8_t n_flags; /* Node flags */
uint16_t n_mode; /* File mode for fstat() */ uint16_t n_mode; /* File mode for fstat() */
time_t n_atime; /* File access time */ time_t n_atime; /* File access time */
time_t n_mtime; /* File modification time */
time_t n_ctime; /* File creation time */ time_t n_ctime; /* File creation time */
struct timespec n_timestamp; /* Timestamp (modification time) */
nfsfh_t n_fhandle; /* NFS File Handle */ nfsfh_t n_fhandle; /* NFS File Handle */
nfsfh_t n_pfhandle; /* NFS File Handle of parent */ nfsfh_t n_pfhandle; /* NFS File Handle of parent */
uint64_t n_size; /* Current size of file */ uint64_t n_size; /* Current size of file */
......
...@@ -563,7 +563,8 @@ void nfs_attrupdate(struct nfsnode *np, struct nfs_fattr *attributes) ...@@ -563,7 +563,8 @@ void nfs_attrupdate(struct nfsnode *np, struct nfs_fattr *attributes)
np->n_size = fxdr_hyper(&attributes->fa_size); np->n_size = fxdr_hyper(&attributes->fa_size);
fxdr_nfsv3time(&attributes->fa_mtime, &ts); fxdr_nfsv3time(&attributes->fa_mtime, &ts);
np->n_mtime = ts.tv_sec; np->n_timestamp.tv_sec = ts.tv_sec;
np->n_timestamp.tv_nsec = ts.tv_nsec;
fxdr_nfsv3time(&attributes->fa_ctime, &ts); fxdr_nfsv3time(&attributes->fa_ctime, &ts);
np->n_ctime = ts.tv_sec; np->n_ctime = ts.tv_sec;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册