9pfs: add some file operation hooks
v2 cover 9pfs: add some file operation hooks
For being able to store the Xenstore state in preparation of a live update operation, 9pfront is needing support for fstat and lseek.
Changes in V2:
- addressed comment for patch 1
Juergen Gross (2):
9pfs: add fstat file operation hook
9pfs: add lseek file operation hook
9pfront.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+)
Signature · 1 line
2.43.0
PATCH v2 1/2 9pfs: add fstat file operation hook
Add a file operations fstat hook to the 9pfs frontend.
---
V2:
- or file access mode into st_mode (Jason Andryuk)
--- 9pfront.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+)
9pfront.c +29 -0
@@ -85,6 +85,8 @@ struct file_9pfs {#define P9_QID_SIZE 13 +#define QID_TYPE_DIR 0x80/* Applies to qid[0]. */ +struct p9_header {uint32_t size;uint8_t cmd;
@@ -950,6 +952,32 @@ static int write_9pfs(struct file *file, const void *buf, size_t nbytes)return ret; } +static int fstat_9pfs (struct file *file,struct stat *buf) +{ +struct file_9pfs *f9pfs = file->filedata; +struct p9_stat stat; +int ret; + + ret =p9_stat (f9pfs->dev, f9pfs->fid, &stat); +if ( ret ) + { + errno =EIO ; +return -1 ; + } + + buf->st_mode = (stat.qid[0 ] ==QID_TYPE_DIR ) ?S_IFDIR :S_IFREG ; + buf->st_mode |= stat.mode &0777 ; + buf->st_atime = stat.atime; + buf->st_mtime = stat.mtime; + buf->st_size = stat.length; + buf->st_uid = stat.n_uid; + buf->st_gid = stat.n_gid; + +free_stat (&stat); + +return 0 ; +} +static int close_9pfs (struct file *file) {struct file_9pfs *f9pfs = file->filedata;
@@ -1296,6 +1324,7 @@ static const struct file_ops ops_9pfs = { .read = read_9pfs, .write = write_9pfs, .close = close_9pfs, + .fstat = fstat_9pfs, }; __attribute__((constructor))
Signature · 1 line
2.43.0
Re: [MINI-OS PATCH v2 1/2] 9pfs: add fstat file operation hook
Juergen Gross, le ven. 21 mars 2025 10:31:44 +0100, a ecrit:
Quoted 35 lines
Add a file operations fstat hook to the 9pfs frontend.
Signed-off-by Juergen Gross <[email protected]>Reviewed-by Jason Andryuk <[email protected]>---
V2:
- or file access mode intost_mode(Jason Andryuk)--- 9pfront.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+)9pfront.c +9
-0@@ -85,6 +85,8 @@ struct file_9pfs {#define P9_QID_SIZE 13 +#define QID_TYPE_DIR 0x80/* Applies to qid[0]. */ +struct p9_header {uint32_t size;uint8_t cmd;@@ -950,6 +952,32 @@ static int write_9pfs(struct file *file, const void *buf, size_t nbytes)return ret; } +static int fstat_9pfs (struct file *file,struct stat *buf) +{ +struct file_9pfs *f9pfs = file->filedata; +struct p9_stat stat; +int ret; + + ret =p9_stat (f9pfs->dev, f9pfs->fid, &stat);
9pfront.c static int write_9pfs(struct file *file, const void *buf, size_t nbytes) · line 971
Quoted 10 lines
9pfront.c +10
-0+if ( ret ) + { + errno =EIO ; +return -1 ; + } + + buf->st_mode = (stat.qid[0 ] ==QID_TYPE_DIR ) ?S_IFDIR :S_IFREG ; + buf->st_mode |= stat.mode &0777 ; + buf->st_atime = stat.atime; + buf->st_mtime = stat.mtime;
Should we perhaps also fill st_ctime? Leaving it at 0 could surprise other software layers.
Quoted 23 lines
9pfront.c +10
-0+ buf->st_size = stat.length; + buf->st_uid = stat.n_uid; + buf->st_gid = stat.n_gid; + +free_stat (&stat); + +return 0 ; +} +static int close_9pfs (struct file *file) {struct file_9pfs *f9pfs = file->filedata;@@ -1296,6 +1324,7 @@ static const struct file_ops ops_9pfs = { .read = read_9pfs, .write = write_9pfs, .close = close_9pfs, + .fstat = fstat_9pfs, }; __attribute__((constructor))Signature · 1 line
2.43.0
Re: [MINI-OS PATCH v2 1/2] 9pfs: add fstat file operation hook
Quoted 41 lines · Samuel Thibault
Juergen Gross, le ven. 21 mars 2025 10:31:44 +0100, a ecrit:
Quoted 40 lines
Add a file operations fstat hook to the 9pfs frontend.
Signed-off-by Juergen Gross <[email protected]>Reviewed-by Jason Andryuk <[email protected]>---
V2:
- or file access mode intost_mode(Jason Andryuk)--- 9pfront.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+)9pfront.c +14
-0@@ -85,6 +85,8 @@ struct file_9pfs {#define P9_QID_SIZE 13 +#define QID_TYPE_DIR 0x80/* Applies to qid[0]. */ +struct p9_header {uint32_t size;uint8_t cmd;@@ -950,6 +952,32 @@ static int write_9pfs(struct file *file, const void *buf, size_t nbytes)return ret; } +static int fstat_9pfs (struct file *file,struct stat *buf) +{ +struct file_9pfs *f9pfs = file->filedata; +struct p9_stat stat; +int ret; + + ret =p9_stat (f9pfs->dev, f9pfs->fid, &stat); +if ( ret ) + { + errno =EIO ; +return -1 ; + }
Quoted 8 lines
9pfront.c static int write_9pfs(struct file *file, const void *buf, size_t nbytes) · line 971
Quoted 5 lines
9pfront.c +5
-0+ + buf->st_mode = (stat.qid[0 ] ==QID_TYPE_DIR ) ?S_IFDIR :S_IFREG ; + buf->st_mode |= stat.mode &0777 ; + buf->st_atime = stat.atime; + buf->st_mtime = stat.mtime;Should we perhaps also fill
st_ctime? Leaving it at 0 could surprise other software layers.
I can set it to the same value as st_mtime. I don't think there is a way to get the "real" ctime value via the 9p protocol.
Juergen
Samuel Thibault
Reviewed-byRe: [MINI-OS PATCH v2 1/2] 9pfs: add fstat file operation hook
Jürgen Groß, le dim. 23 mars 2025 15:57:16 +0100, a ecrit:
Quoted 48 lines · Samuel Thibault
Quoted 38 lines
Juergen Gross, le ven. 21 mars 2025 10:31:44 +0100, a ecrit:
Quoted 37 lines
Add a file operations fstat hook to the 9pfs frontend.
Signed-off-by Juergen Gross <[email protected]>Reviewed-by Jason Andryuk <[email protected]>---
V2:
- or file access mode intost_mode(Jason Andryuk)--- 9pfront.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+)9pfront.c +14
-0@@ -85,6 +85,8 @@ struct file_9pfs {#define P9_QID_SIZE 13 +#define QID_TYPE_DIR 0x80/* Applies to qid[0]. */ +struct p9_header {uint32_t size;uint8_t cmd;@@ -950,6 +952,32 @@ static int write_9pfs(struct file *file, const void *buf, size_t nbytes)return ret; } +static int fstat_9pfs (struct file *file,struct stat *buf) +{ +struct file_9pfs *f9pfs = file->filedata; +struct p9_stat stat; +int ret; + + ret =p9_stat (f9pfs->dev, f9pfs->fid, &stat); +if ( ret ) + { + errno =EIO ; +return -1 ; + }Quoted 8 lines
9pfront.c static int write_9pfs(struct file *file, const void *buf, size_t nbytes) · line 971
Quoted 5 lines
9pfront.c +5
-0+ + buf->st_mode = (stat.qid[0 ] ==QID_TYPE_DIR ) ?S_IFDIR :S_IFREG ; + buf->st_mode |= stat.mode &0777 ; + buf->st_atime = stat.atime; + buf->st_mtime = stat.mtime;Should we perhaps also fill
st_ctime? Leaving it at 0 could surprise other software layers.
Quoted 1 line
I can set it to the same value as
st_mtime.
That'd be preferrable, yes.
With that,
Thanks!
Samuel
Re: [MINI-OS PATCH v2 1/2] 9pfs: add fstat file operation hook
In reply to Jürgen GroßQuoted 51 lines · Jürgen Groß
Quoted 41 lines · Samuel Thibault
Juergen Gross, le ven. 21 mars 2025 10:31:44 +0100, a ecrit:
Quoted 40 lines
Add a file operations fstat hook to the 9pfs frontend.
Signed-off-by Juergen Gross <[email protected]>Reviewed-by Jason Andryuk <[email protected]>---
V2:
- or file access mode intost_mode(Jason Andryuk)--- 9pfront.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+)9pfront.c +14
-0@@ -85,6 +85,8 @@ struct file_9pfs {#define P9_QID_SIZE 13 +#define QID_TYPE_DIR 0x80/* Applies to qid[0]. */ +struct p9_header {uint32_t size;uint8_t cmd;@@ -950,6 +952,32 @@ static int write_9pfs(struct file *file, const void *buf, size_t nbytes)return ret; } +static int fstat_9pfs (struct file *file,struct stat *buf) +{ +struct file_9pfs *f9pfs = file->filedata; +struct p9_stat stat; +int ret; + + ret =p9_stat (f9pfs->dev, f9pfs->fid, &stat); +if ( ret ) + { + errno =EIO ; +return -1 ; + }Quoted 8 lines
9pfront.c static int write_9pfs(struct file *file, const void *buf, size_t nbytes) · line 971
Quoted 5 lines
9pfront.c +5
-0+ + buf->st_mode = (stat.qid[0 ] ==QID_TYPE_DIR ) ?S_IFDIR :S_IFREG ; + buf->st_mode |= stat.mode &0777 ; + buf->st_atime = stat.atime; + buf->st_mtime = stat.mtime;Should we perhaps also fill
st_ctime? Leaving it at 0 could surprise other software layers.
Quoted 1 line
I can set it to the same value as
st_mtime.
Maybe the smaller of atime and mtime?
Jan
Quoted 5 lines
I don't think there is a way
to get the "real" ctime value via the 9p protocol.Juergen
Re: [MINI-OS PATCH v2 1/2] 9pfs: add fstat file operation hook
Jan Beulich, le lun. 24 mars 2025 11:21:48 +0100, a ecrit:
Quoted 52 lines · Jürgen Groß
Quoted 51 lines · Samuel Thibault
Quoted 49 lines
Juergen Gross, le ven. 21 mars 2025 10:31:44 +0100, a ecrit:
Quoted 35 lines
Add a file operations fstat hook to the 9pfs frontend.
Signed-off-by Juergen Gross <[email protected]>Reviewed-by Jason Andryuk <[email protected]>---
V2:
- or file access mode intost_mode(Jason Andryuk)--- 9pfront.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+)9pfront.c +9
-0@@ -85,6 +85,8 @@ struct file_9pfs {#define P9_QID_SIZE 13 +#define QID_TYPE_DIR 0x80/* Applies to qid[0]. */ +struct p9_header {uint32_t size;uint8_t cmd;@@ -950,6 +952,32 @@ static int write_9pfs(struct file *file, const void *buf, size_t nbytes)return ret; } +static int fstat_9pfs (struct file *file,struct stat *buf) +{ +struct file_9pfs *f9pfs = file->filedata; +struct p9_stat stat; +int ret; + + ret =p9_stat (f9pfs->dev, f9pfs->fid, &stat);9pfront.c static int write_9pfs(struct file *file, const void *buf, size_t nbytes) · line 971
Quoted 10 lines
9pfront.c +10
-0+if ( ret ) + { + errno =EIO ; +return -1 ; + } + + buf->st_mode = (stat.qid[0 ] ==QID_TYPE_DIR ) ?S_IFDIR :S_IFREG ; + buf->st_mode |= stat.mode &0777 ; + buf->st_atime = stat.atime; + buf->st_mtime = stat.mtime;Should we perhaps also fill
st_ctime? Leaving it at 0 could surprise other software layers.
Quoted 3 lines
Quoted 1 line
I can set it to the same value as
st_mtime.Maybe the smaller of atime and mtime?
That'd be better, yes.
Samuel
Re: [MINI-OS PATCH v2 1/2] 9pfs: add fstat file operation hook
Quoted 53 lines · Samuel Thibault
Jan Beulich, le lun. 24 mars 2025 11:21:48 +0100, a ecrit:
Quoted 52 lines · Jürgen Groß
Quoted 51 lines · Samuel Thibault
Quoted 49 lines
Juergen Gross, le ven. 21 mars 2025 10:31:44 +0100, a ecrit:
Quoted 35 lines
Add a file operations fstat hook to the 9pfs frontend.
Signed-off-by Juergen Gross <[email protected]>Reviewed-by Jason Andryuk <[email protected]>---
V2:
- or file access mode intost_mode(Jason Andryuk)--- 9pfront.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+)9pfront.c +9
-0@@ -85,6 +85,8 @@ struct file_9pfs {#define P9_QID_SIZE 13 +#define QID_TYPE_DIR 0x80/* Applies to qid[0]. */ +struct p9_header {uint32_t size;uint8_t cmd;@@ -950,6 +952,32 @@ static int write_9pfs(struct file *file, const void *buf, size_t nbytes)return ret; } +static int fstat_9pfs (struct file *file,struct stat *buf) +{ +struct file_9pfs *f9pfs = file->filedata; +struct p9_stat stat; +int ret; + + ret =p9_stat (f9pfs->dev, f9pfs->fid, &stat);9pfront.c static int write_9pfs(struct file *file, const void *buf, size_t nbytes) · line 971
Quoted 10 lines
9pfront.c +10
-0+if ( ret ) + { + errno =EIO ; +return -1 ; + } + + buf->st_mode = (stat.qid[0 ] ==QID_TYPE_DIR ) ?S_IFDIR :S_IFREG ; + buf->st_mode |= stat.mode &0777 ; + buf->st_atime = stat.atime; + buf->st_mtime = stat.mtime;Should we perhaps also fill
st_ctime? Leaving it at 0 could surprise other software layers.
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
I can set it to the same value as
st_mtime.Maybe the smaller of atime and mtime?
That'd be better, yes.
According to the references I could find ctime is changed whenever either file contents OR file status (uid, gid, permissions) are modified. So using the same value as mtime seems appropriate.
Juergen
Re: [MINI-OS PATCH v2 1/2] 9pfs: add fstat file operation hook
Quoted 56 lines · Jürgen Groß
Quoted 55 lines · Samuel Thibault
Jan Beulich, le lun. 24 mars 2025 11:21:48 +0100, a ecrit:
Quoted 54 lines · Jürgen Groß
Quoted 52 lines · Samuel Thibault
Quoted 41 lines
Juergen Gross, le ven. 21 mars 2025 10:31:44 +0100, a ecrit:
Quoted 40 lines
Add a file operations fstat hook to the 9pfs frontend.
Signed-off-by Juergen Gross <[email protected]>Reviewed-by Jason Andryuk <[email protected]>---
V2:
- or file access mode intost_mode(Jason Andryuk)--- 9pfront.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+)9pfront.c +14
-0@@ -85,6 +85,8 @@ struct file_9pfs {#define P9_QID_SIZE 13 +#define QID_TYPE_DIR 0x80/* Applies to qid[0]. */ +struct p9_header {uint32_t size;uint8_t cmd;@@ -950,6 +952,32 @@ static int write_9pfs(struct file *file, const void *buf, size_t nbytes)return ret; } +static int fstat_9pfs (struct file *file,struct stat *buf) +{ +struct file_9pfs *f9pfs = file->filedata; +struct p9_stat stat; +int ret; + + ret =p9_stat (f9pfs->dev, f9pfs->fid, &stat); +if ( ret ) + { + errno =EIO ; +return -1 ; + }Quoted 8 lines
9pfront.c static int write_9pfs(struct file *file, const void *buf, size_t nbytes) · line 971
Quoted 5 lines
9pfront.c +5
-0+ + buf->st_mode = (stat.qid[0 ] ==QID_TYPE_DIR ) ?S_IFDIR :S_IFREG ; + buf->st_mode |= stat.mode &0777 ; + buf->st_atime = stat.atime; + buf->st_mtime = stat.mtime;Should we perhaps also fill
st_ctime? Leaving it at 0 could surprise other software layers.I can set it to the same value as
st_mtime.
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
Maybe the smaller of atime and mtime?
That'd be better, yes.
According to the references I could find ctime is changed whenever either file contents OR file status (uid, gid, permissions) are modified. So using the same value as mtime seems appropriate.
Hmm, yes, one always learns something new. Having come from the DOS/Windows world originally, 'c' in the name to me only ever could stand for "create". When really, as you say, it's "change". I'm sorry for introducing confusion here.
Jan
PATCH v2 2/2 9pfs: add lseek file operation hook
In reply to Juergen GrossAdd a file operations lseek hook to the 9pfs frontend. Just use the lseek_default() implementation.
--- 9pfront.c | 1 + 1 file changed, 1 insertion(+)
9pfront.c +1 -0
@@ -1325,6 +1325,7 @@ static const struct file_ops ops_9pfs = { .write = write_9pfs, .close = close_9pfs, .fstat = fstat_9pfs, + .lseek = lseek_default, }; __attribute__((constructor))
Signature · 1 line
2.43.0
Re: [MINI-OS PATCH v2 2/2] 9pfs: add lseek file operation hook
Juergen Gross, le ven. 21 mars 2025 10:31:45 +0100, a ecrit:
Quoted 5 lines
Add a file operations lseek hook to the 9pfs frontend. Just use the
lseek_default()implementation.Signed-off-by Juergen Gross <[email protected]>Reviewed-by Jason Andryuk <[email protected]>
Quoted 19 lines
--- 9pfront.c | 1 + 1 file changed, 1 insertion(+)9pfront.c +1
-0@@ -1325,6 +1325,7 @@ static const struct file_ops ops_9pfs = { .write = write_9pfs, .close = close_9pfs, .fstat = fstat_9pfs, + .lseek = lseek_default, }; __attribute__((constructor))Signature · 1 line
2.43.0