Skip to content

Conversation

@jlaitine
Copy link
Contributor

…alls

  • Add truncate, mmap and munmap into file_operations and remove them from ioctl definitions.

  • Move truncate to be common for mountpt_operations and file_operations

  • Modify all drivers to initialize the operations struct accordingly

Signed-off-by: Jukka Laitinen jukkax@ssrc.tii.ae

Summary

  • IOCTLs are ment for communication from userspace application to the drivers. It doesn't make sense for an application to perform a direct IOCTL (such as FIOC_MMAP, FIOC_MUNMAP or FIOC_TRUNCATE). Application should always use posix mmap, munmap and truncate calls instead.

  • For mmap, munmap and truncate there is a syscall lookup already in place in nuttx - there is no ioctl needed for the userspace-kernel communication

  • Especially for "unmap", the ioctl doesn't make sense, since file_ioctl is supposed to work on a file pointer. But unmap cannot be done on a file. Even when unmapping a previously mapped "file", unmap can only work on inode, since there may not be an open file, or even a linked inode present. It must be possible to do "munmap" for a mapped file, even if the actual file is closed and/or deleted after mapping.

Impact

Cleanup of the interfaces, doesn't change the current functionality but makes it easier to add new

Testing

Inspected only.

@jlaitine jlaitine force-pushed the add_mmap_munmap_and_truncate_into_file_operations branch 7 times, most recently from f0fe4c0 to 37682c0 Compare December 29, 2022 08:10
@jlaitine
Copy link
Contributor Author

Will gradually fix any issues in CI for this PR, lets review when it passes

@jlaitine jlaitine force-pushed the add_mmap_munmap_and_truncate_into_file_operations branch 4 times, most recently from 8821e1b to e459aed Compare December 29, 2022 16:31
@jlaitine
Copy link
Contributor Author

I think all drivers are now fixed for the changed struct definition. @xiaoxiang781216, this is the change I proposed on the nuttx-dev list.

@xiaoxiang781216
Copy link
Contributor

Sure, I will review in the weekend, thanks to provide a general solution.

@jlaitine jlaitine force-pushed the add_mmap_munmap_and_truncate_into_file_operations branch 4 times, most recently from a67fc33 to 8933509 Compare December 31, 2022 06:34
@jlaitine
Copy link
Contributor Author

forgot to revert changes to fs_rammap.* , that is now back to the original.

@jlaitine jlaitine force-pushed the add_mmap_munmap_and_truncate_into_file_operations branch from 8933509 to 2b08741 Compare December 31, 2022 09:18
@jlaitine
Copy link
Contributor Author

rebased agains current master

@xiaoxiang781216
Copy link
Contributor

@jlaitine many drivers don't need change if all callbacks after ioctl are NULL.

@jlaitine
Copy link
Contributor Author

jlaitine commented Jan 2, 2023

Here I must disagree. You definitely need to change these, since they currently look like this:


  NULL,                      /* write */
   NULL,                      /* seek */
   cxd56_adc_ioctl,           /* ioctl */
   NULL                       /* poll */
 #ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS
   , NULL                     /* unlink */
#endif

Not changing it would leave misleading comments (/* poll / is not the pointer to poll, / unlink */ is not a pointer to unlink etc.).

There are really just two options:

  1. delete all the trailing NULL pointers for all of these
  2. add the new functions in between.

I do the 2) because this preserves the current style

@jlaitine jlaitine force-pushed the add_mmap_munmap_and_truncate_into_file_operations branch from 2b08741 to 30e5980 Compare January 2, 2023 09:17
@xiaoxiang781216
Copy link
Contributor

Here I must disagree. You definitely need to change these, since they currently look like this:


  NULL,                      /* write */
   NULL,                      /* seek */
   cxd56_adc_ioctl,           /* ioctl */
   NULL                       /* poll */
 #ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS
   , NULL                     /* unlink */
#endif

Not changing it would leave misleading comments (/* poll / is not the pointer to poll, / unlink */ is not a pointer to unlink etc.).

There are really just two options:

  1. delete all the trailing NULL pointers for all of these
  2. add the new functions in between.

I do the 2) because this preserves the current style

Yes, that's why I prepare this patch: #8016 to remove the trailing NULL pointer.

@jlaitine jlaitine force-pushed the add_mmap_munmap_and_truncate_into_file_operations branch from 30e5980 to 8451b50 Compare January 2, 2023 09:21
@jlaitine
Copy link
Contributor Author

jlaitine commented Jan 2, 2023

Yes, that's why I prepare this patch: #8016 to remove the trailing NULL pointer.

Sure, I will update this PR as soon as your patch is merged. I see that @acassis already approved it

Removed the changes which are redundant after #8016 is merged

- Add truncate into file_operations
- Move truncate to be common for mountpt_operations and file_operations
- Modify all drivers to initialize the operations struct accordingly

Signed-off-by: Jukka Laitinen <jukkax@ssrc.tii.ae>
@jlaitine jlaitine force-pushed the add_mmap_munmap_and_truncate_into_file_operations branch from 0da2f4d to 7026cc6 Compare January 2, 2023 13:13
@jlaitine jlaitine force-pushed the add_mmap_munmap_and_truncate_into_file_operations branch 2 times, most recently from 9ce80ba to 163fafc Compare January 2, 2023 13:47
- Add mmap into file_operations and remove it from ioctl definitions.
- Add mm_map structure definitions to support future unmapping
- Modify all drivers to initialize the operations struct accordingly

Signed-off-by: Jukka Laitinen <jukkax@ssrc.tii.ae>
@jlaitine jlaitine force-pushed the add_mmap_munmap_and_truncate_into_file_operations branch from 163fafc to 2868628 Compare January 2, 2023 14:01
@acassis acassis merged commit f33dc4d into apache:master Jan 2, 2023
FAR video_mng_t *priv = (FAR video_mng_t *)inode->i_private;
int ret = -EINVAL;

if (map)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's add after get_bufsize:

static size_t get_heapsize(FAR video_type_inf_t *type_inf)
{
  return type_inf->bufinf.container_size *
         get_bufsize(&type_inf->fmt[VIDEO_FMT_MAIN]);
}

and do more check here:

if (map->offset >= 0 && map->offset < get_heapsize(&priv->video_inf) &&
    map->offset + map->length <= get_heapsize(&priv->video_inf))

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @xiaoxiang781216, I think you add it while I was hitting the merge button!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will create a patch fix the remain issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, thanks!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is the patch: #8021

ret = filep->f_inode->u.i_ops->mmap(filep, &map);
if (ret == OK)
{
*mapped = (void *)map.vaddr;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add FAR to void *

Comment on lines +151 to +155
NULL, /* sq_entry_t */
start, length, offset,
prot, flags,
NULL, /* priv */
NULL /* munmap */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to fix indentations and place 1 init per line

@jlaitine jlaitine deleted the add_mmap_munmap_and_truncate_into_file_operations branch January 10, 2023 17:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants