Skip to contentSkip to conversation

virtiofsd: fix compile error if 'F_OFD_GETLK' not defined

PATCH Superseded piaojun 4 participants 8 messages Jul 30, 2019 – Aug 2, 2019

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

piaojun

author
#0 lore raw

PATCH 1/1 virtiofsd: fix compile error if 'F_OFD_GETLK' not defined

Use F_GETLK for fcntl when F_OFD_GETLK not defined.

---
 contrib/virtiofsd/passthrough_ll.c | 9 +++++++++
 1 file changed, 9 insertions(+)
contrib/virtiofsd/passthrough_ll.c +9 -0
index 9ae1381..757785b 100644
@@ -1619,7 +1619,11 @@ static void lo_getlk(fuse_req_t req, fuse_ino_t ino,
 		return;
 	}
 
+#ifdef F_OFD_GETLK
 	ret = fcntl(plock->fd, F_OFD_GETLK, lock);
+#else
+	ret = fcntl(plock->fd, F_GETLK, lock);
+#endif
 	if (ret == -1)
 		saverr = errno;
 	pthread_mutex_unlock(&inode->plock_mutex);
@@ -1668,7 +1672,12 @@ static void lo_setlk(fuse_req_t req, fuse_ino_t ino,
 
 	/* TODO: Is it alright to modify flock? */
 	lock->l_pid = 0;
+
+#ifdef F_OFD_GETLK
 	ret = fcntl(plock->fd, F_OFD_SETLK, lock);
+#else
+	ret = fcntl(plock->fd, F_SETLK, lock);
+#endif
 	if (ret == -1) {
 		saverr = errno;
 	}
#1 lore raw
Quoted 1 line · piaojun

Use F_GETLK for fcntl when F_OFD_GETLK not defined.

Use F_GETLK/F_SETLK for fcntl when F_OFD_GETLK/F_OFD_SETLK not defined.

Quoted 23 lines
---
  contrib/virtiofsd/passthrough_ll.c | 9 +++++++++
  1 file changed, 9 insertions(+)
contrib/virtiofsd/passthrough_ll.c +4 -0
index 9ae1381..757785b 100644
@@ -1619,7 +1619,11 @@ static void lo_getlk(fuse_req_t req, fuse_ino_t ino,
  		return;
  	}
 
+#ifdef F_OFD_GETLK
  	ret = fcntl(plock->fd, F_OFD_GETLK, lock);
+#else
+	ret = fcntl(plock->fd, F_GETLK, lock);
+#endif
  	if (ret == -1)
  		saverr = errno;
  	pthread_mutex_unlock(&inode->plock_mutex);

contrib/virtiofsd/passthrough_ll.c static void lo_setlk(fuse_req_t req, fuse_ino_t ino, · line 1676

Quoted 5 lines
contrib/virtiofsd/passthrough_ll.c +2 -0
@@ -1668,7 +1672,12 @@ static void lo_setlk(fuse_req_t req, fuse_ino_t ino,
 
  	/* TODO: Is it alright to modify flock? */
  	lock->l_pid = 0;
+
+#ifdef F_OFD_GETLK

This checks for F_OFD_GETLK but uses F_OFD_SETLK (albeit unlikely one being defined without the other)

contrib/virtiofsd/passthrough_ll.c static void lo_setlk(fuse_req_t req, fuse_ino_t ino, · line 1683

Quoted 8 lines
contrib/virtiofsd/passthrough_ll.c +3 -0
  	ret = fcntl(plock->fd, F_OFD_SETLK, lock);
+#else
+	ret = fcntl(plock->fd, F_SETLK, lock);
+#endif
  	if (ret == -1) {
  		saverr = errno;
  	}

Might qemu_lock_fd()/qemu_unlock_fd() in util/osdep.c be useful to hide this instead?

Regards,
Liam

author
#2 lore raw

Hi Liam,

Quoted 30 lines · Liam Merwick
Quoted 1 line · piaojun

Use F_GETLK for fcntl when F_OFD_GETLK not defined.

Use F_GETLK/F_SETLK for fcntl when F_OFD_GETLK/F_OFD_SETLK not defined.

Quoted 24 lines
---
  contrib/virtiofsd/passthrough_ll.c | 9 +++++++++
  1 file changed, 9 insertions(+)
contrib/virtiofsd/passthrough_ll.c +4 -0
index 9ae1381..757785b 100644
@@ -1619,7 +1619,11 @@ static void lo_getlk(fuse_req_t req, fuse_ino_t ino,
          return;
      }
 
+#ifdef F_OFD_GETLK
      ret = fcntl(plock->fd, F_OFD_GETLK, lock);
+#else
+    ret = fcntl(plock->fd, F_GETLK, lock);
+#endif
      if (ret == -1)
          saverr = errno;
      pthread_mutex_unlock(&inode->plock_mutex);
@@ -1668,7 +1672,12 @@ static void lo_setlk(fuse_req_t req, fuse_ino_t ino,
 
Quoted 7 lines

contrib/virtiofsd/passthrough_ll.c static void lo_setlk(fuse_req_t req, fuse_ino_t ino, · line 1676

Quoted 4 lines
contrib/virtiofsd/passthrough_ll.c +2 -0
      /* TODO: Is it alright to modify flock? */
      lock->l_pid = 0;
+
+#ifdef F_OFD_GETLK

This checks for F_OFD_GETLK but uses F_OFD_SETLK (albeit unlikely one being defined without the other)

Right, F_OFD_SETLK looks better.

Quoted 11 lines

contrib/virtiofsd/passthrough_ll.c static void lo_setlk(fuse_req_t req, fuse_ino_t ino, · line 1683

Quoted 10 lines
contrib/virtiofsd/passthrough_ll.c +3 -0
      ret = fcntl(plock->fd, F_OFD_SETLK, lock);
+#else
+    ret = fcntl(plock->fd, F_SETLK, lock);
+#endif
      if (ret == -1) {
          saverr = errno;
      }

Might qemu_lock_fd()/qemu_unlock_fd() in util/osdep.c be useful to hide this instead?

Yes, I'm trying re-write do_getlk/setlk with qemu_lock_fd, and thanks for your suggestion.

Thanks,
Jun

Quoted 4 lines

Regards,
Liam

#3 lore raw
In reply to piaojun
Quoted 1 line · piaojun

Use F_GETLK for fcntl when F_OFD_GETLK not defined.

Which system are you hitting this problem on?

The problem with F_GETLK is that it is NOT as safe as F_OFD_GETLK.

We already have fcntl_op_getlk and qemu_probe_lock_ops() in util/osdep.c to not only determine which form to use, but also to emit a warning to the end user if we had to fall back to the unsafe F_GETLK. Why is your code not reusing that logic?

Quoted 11 lines
---
 contrib/virtiofsd/passthrough_ll.c | 9 +++++++++
 1 file changed, 9 insertions(+)
contrib/virtiofsd/passthrough_ll.c +0 -0
index 9ae1381..757785b 100644

contrib/virtiofsd/passthrough_ll.c static void lo_getlk(fuse_req_t req, fuse_ino_t ino, · line 1626

Quoted 8 lines
contrib/virtiofsd/passthrough_ll.c +4 -0
@@ -1619,7 +1619,11 @@ static void lo_getlk(fuse_req_t req, fuse_ino_t ino,
 		return;
 	}
 
+#ifdef F_OFD_GETLK
 	ret = fcntl(plock->fd, F_OFD_GETLK, lock);
+#else
+	ret = fcntl(plock->fd, F_GETLK, lock);
+#endif

Hmm. Since this is in contrib, you are trying to compile something that is independent of util/osdep.c (at least, I assume that's the case, as contrib/virtiofsd/ is not even part of qemu.git master yet - in which case, why is this not being squashed in to the patch introducing that file, rather than sent standalone). On the other hand, that raises the question - who is trying to use virtiofsd on a kernel that is too old to provid F_OFD_GETLK? Isn't the whole point of virtiofsd to be speeding up modern usage, at which point an old kernel is just gumming up the works? It seems like you are better off letting compilation fail on a system that is too old to support decent F_OFD_GETLK, rather than silently falling back to something that is unsafe.

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org
author
#4 lore raw

Hi Eric,

Quoted 11 lines · Eric Blake
Quoted 1 line · piaojun

Use F_GETLK for fcntl when F_OFD_GETLK not defined.

Which system are you hitting this problem on?

The problem with F_GETLK is that it is NOT as safe as F_OFD_GETLK.

We already have fcntl_op_getlk and qemu_probe_lock_ops() in util/osdep.c to not only determine which form to use, but also to emit a warning to the end user if we had to fall back to the unsafe F_GETLK. Why is your code not reusing that logic?

virtiofsd compile error due to missed 'F_OFD_GETLK'. My kernel version is 3.10.

linux-PUALcm:/home/code/virtiofs/qemu # make -j 8 virtiofsd

make[1]: Entering directory /home/code/virtiofs/qemu/slirp' make[1]: Nothing to be done for all'.
make[1]: Leaving directory `/home/code/virtiofs/qemu/slirp'
CHK version_gen.h

  CC      contrib/virtiofsd/passthrough_ll.o
  CC      qapi/qapi-clone-visitor.o
  CC      qapi/qmp-event.o
  CC      qapi/qapi-util.o
  CC      qapi/qapi-builtin-types.o
  CC      qapi/qapi-types-audio.o
  CC      qapi/qapi-types-authz.o
  CC      qapi/qapi-types-block-core.o
contrib/virtiofsd/passthrough_ll.c: In function ‘lo_getlk’:
contrib/virtiofsd/passthrough_ll.c:1622:25: error: ‘F_OFD_GETLK’ undeclared (first use in this function)
  ret = fcntl(plock->fd, F_OFD_GETLK, lock);
                         ^

contrib/virtiofsd/passthrough_ll.c:1622:25: note: each undeclared identifier is reported only once for each function it appears in contrib/virtiofsd/passthrough_ll.c: In function ‘lo_setlk’:
contrib/virtiofsd/passthrough_ll.c:1671:25: error: ‘F_OFD_SETLK’ undeclared (first use in this function)

Quoted 24 lines
Quoted 12 lines
---
 contrib/virtiofsd/passthrough_ll.c | 9 +++++++++
 1 file changed, 9 insertions(+)
contrib/virtiofsd/passthrough_ll.c +0 -0
index 9ae1381..757785b 100644

contrib/virtiofsd/passthrough_ll.c static void lo_getlk(fuse_req_t req, fuse_ino_t ino, · line 1626

Quoted 8 lines
contrib/virtiofsd/passthrough_ll.c +4 -0
@@ -1619,7 +1619,11 @@ static void lo_getlk(fuse_req_t req, fuse_ino_t ino,
 		return;
 	}
 
+#ifdef F_OFD_GETLK
 	ret = fcntl(plock->fd, F_OFD_GETLK, lock);
+#else
+	ret = fcntl(plock->fd, F_GETLK, lock);
+#endif

Hmm. Since this is in contrib, you are trying to compile something that is independent of util/osdep.c (at least, I assume that's the case, as contrib/virtiofsd/ is not even part of qemu.git master yet - in which

Quoted 8 lines

case, why is this not being squashed in to the patch introducing that file, rather than sent standalone). On the other hand, that raises the question - who is trying to use virtiofsd on a kernel that is too old to provid F_OFD_GETLK? Isn't the whole point of virtiofsd to be speeding up modern usage, at which point an old kernel is just gumming up the works? It seems like you are better off letting compilation fail on a system that is too old to support decent F_OFD_GETLK, rather than silently falling back to something that is unsafe.

Perhaps reusing qemu_lock_fd() looks a better way to solve this.

Thanks,
Jun

Quoted 1 line
#5 lore raw
In reply to Eric Blake
Quoted 35 lines · * Eric Blake ([email protected]) wrote:
Quoted 1 line · piaojun

Use F_GETLK for fcntl when F_OFD_GETLK not defined.

Which system are you hitting this problem on?

The problem with F_GETLK is that it is NOT as safe as F_OFD_GETLK.

We already have fcntl_op_getlk and qemu_probe_lock_ops() in util/osdep.c to not only determine which form to use, but also to emit a warning to the end user if we had to fall back to the unsafe F_GETLK. Why is your code not reusing that logic?

Quoted 11 lines
---
 contrib/virtiofsd/passthrough_ll.c | 9 +++++++++
 1 file changed, 9 insertions(+)
contrib/virtiofsd/passthrough_ll.c +0 -0
index 9ae1381..757785b 100644

contrib/virtiofsd/passthrough_ll.c static void lo_getlk(fuse_req_t req, fuse_ino_t ino, · line 1626

Quoted 8 lines
contrib/virtiofsd/passthrough_ll.c +4 -0
@@ -1619,7 +1619,11 @@ static void lo_getlk(fuse_req_t req, fuse_ino_t ino,
 		return;
 	}
 
+#ifdef F_OFD_GETLK
 	ret = fcntl(plock->fd, F_OFD_GETLK, lock);
+#else
+	ret = fcntl(plock->fd, F_GETLK, lock);
+#endif

Hmm. Since this is in contrib, you are trying to compile something that is independent of util/osdep.c (at least, I assume that's the case, as contrib/virtiofsd/ is not even part of qemu.git master yet - in which

Quoted 8 lines

case, why is this not being squashed in to the patch introducing that file, rather than sent standalone). On the other hand, that raises the question - who is trying to use virtiofsd on a kernel that is too old to provid F_OFD_GETLK? Isn't the whole point of virtiofsd to be speeding up modern usage, at which point an old kernel is just gumming up the works? It seems like you are better off letting compilation fail on a system that is too old to support decent F_OFD_GETLK, rather than silently falling back to something that is unsafe.

It is, but I guess the answer here is someone wanted to build on RHEL7.

Dave

Quoted 14 lines
Signature · 13 lines
-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org





_______________________________________________
Virtio-fs mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/virtio-fs

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

#6 lore raw
Quoted 45 lines · * Dr. David Alan Gilbert ([email protected]) wrote:
Quoted 35 lines · * Eric Blake ([email protected]) wrote:
Quoted 1 line · piaojun

Use F_GETLK for fcntl when F_OFD_GETLK not defined.

Which system are you hitting this problem on?

The problem with F_GETLK is that it is NOT as safe as F_OFD_GETLK.

We already have fcntl_op_getlk and qemu_probe_lock_ops() in util/osdep.c to not only determine which form to use, but also to emit a warning to the end user if we had to fall back to the unsafe F_GETLK. Why is your code not reusing that logic?

Quoted 11 lines
---
 contrib/virtiofsd/passthrough_ll.c | 9 +++++++++
 1 file changed, 9 insertions(+)
contrib/virtiofsd/passthrough_ll.c +0 -0
index 9ae1381..757785b 100644

contrib/virtiofsd/passthrough_ll.c static void lo_getlk(fuse_req_t req, fuse_ino_t ino, · line 1626

Quoted 8 lines
contrib/virtiofsd/passthrough_ll.c +4 -0
@@ -1619,7 +1619,11 @@ static void lo_getlk(fuse_req_t req, fuse_ino_t ino,
 		return;
 	}
 
+#ifdef F_OFD_GETLK
 	ret = fcntl(plock->fd, F_OFD_GETLK, lock);
+#else
+	ret = fcntl(plock->fd, F_GETLK, lock);
+#endif

Hmm. Since this is in contrib, you are trying to compile something that is independent of util/osdep.c (at least, I assume that's the case, as contrib/virtiofsd/ is not even part of qemu.git master yet - in which

Quoted 8 lines

case, why is this not being squashed in to the patch introducing that file, rather than sent standalone). On the other hand, that raises the question - who is trying to use virtiofsd on a kernel that is too old to provid F_OFD_GETLK? Isn't the whole point of virtiofsd to be speeding up modern usage, at which point an old kernel is just gumming up the works? It seems like you are better off letting compilation fail on a system that is too old to support decent F_OFD_GETLK, rather than silently falling back to something that is unsafe.

Quoted 1 line

It is, but I guess the answer here is someone wanted to build on RHEL7.

although looking at the tools it went in 7.6

Dave

Quoted 17 lines

Dave

Quoted 14 lines
Signature · 13 lines
-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org





_______________________________________________
Virtio-fs mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/virtio-fs
Quoted 7 lines

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

_______________________________________________
Virtio-fs mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/virtio-fs

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

author
#7 lore raw

Hi Dave and Eric,

Quoted 46 lines · Dr. David Alan Gilbert
Quoted 45 lines · * Dr. David Alan Gilbert ([email protected]) wrote:
Quoted 43 lines · * Eric Blake ([email protected]) wrote:
Quoted 1 line · piaojun

Use F_GETLK for fcntl when F_OFD_GETLK not defined.

Which system are you hitting this problem on?

The problem with F_GETLK is that it is NOT as safe as F_OFD_GETLK.

We already have fcntl_op_getlk and qemu_probe_lock_ops() in util/osdep.c to not only determine which form to use, but also to emit a warning to the end user if we had to fall back to the unsafe F_GETLK. Why is your code not reusing that logic?

Quoted 11 lines
---
 contrib/virtiofsd/passthrough_ll.c | 9 +++++++++
 1 file changed, 9 insertions(+)
contrib/virtiofsd/passthrough_ll.c +0 -0
index 9ae1381..757785b 100644

contrib/virtiofsd/passthrough_ll.c static void lo_getlk(fuse_req_t req, fuse_ino_t ino, · line 1626

Quoted 8 lines
contrib/virtiofsd/passthrough_ll.c +4 -0
@@ -1619,7 +1619,11 @@ static void lo_getlk(fuse_req_t req, fuse_ino_t ino,
 		return;
 	}
 
+#ifdef F_OFD_GETLK
 	ret = fcntl(plock->fd, F_OFD_GETLK, lock);
+#else
+	ret = fcntl(plock->fd, F_GETLK, lock);
+#endif

Hmm. Since this is in contrib, you are trying to compile something that is independent of util/osdep.c (at least, I assume that's the case, as contrib/virtiofsd/ is not even part of qemu.git master yet - in which case, why is this not being squashed in to the patch introducing that file, rather than sent standalone). On the other hand, that raises the question - who is trying to use virtiofsd on a kernel that is too old to provid F_OFD_GETLK? Isn't the whole point of virtiofsd to be speeding up modern usage, at which point an old kernel is just gumming up the works? It seems like you are better off letting compilation fail on a system that is too old to support decent F_OFD_GETLK, rather than silently falling back to something that is unsafe.

Quoted 6 lines
Quoted 1 line

It is, but I guess the answer here is someone wanted to build on RHEL7.

although looking at the tools it went in 7.6

Dave

Yes, the compile error comes from kernel 3.10, and it seems necessary to solve this. I try to reuse qemu_lock_fd() to compat F_GETLK/F_SETLK, but its semantics differs from fcntl, so I think using #ifdef will be easier.

We could delete F_GETLK/F_SETLK compat when virtiofsd is limited to be built in newer kernel. And I'm glad to hear from other developers.

Thanks,
Jun

Quoted 33 lines
Quoted 17 lines

Dave

Quoted 14 lines
Signature · 13 lines
-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org





_______________________________________________
Virtio-fs mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/virtio-fs
Quoted 7 lines

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

_______________________________________________
Virtio-fs mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/virtio-fs

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

_______________________________________________
Virtio-fs mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/virtio-fs
.