LCOV - code coverage report
Current view: top level - fs/lockd - svcshare.c (source / functions) Hit Total Coverage
Test: gcov_data_raspi2_real_modules_combined.info Lines: 0 39 0.0 %
Date: 2020-09-30 20:25:40 Functions: 0 4 0.0 %
Branches: 0 26 0.0 %

           Branch data     Line data    Source code
       1                 :            : // SPDX-License-Identifier: GPL-2.0
       2                 :            : /*
       3                 :            :  * linux/fs/lockd/svcshare.c
       4                 :            :  *
       5                 :            :  * Management of DOS shares.
       6                 :            :  *
       7                 :            :  * Copyright (C) 1996 Olaf Kirch <okir@monad.swb.de>
       8                 :            :  */
       9                 :            : 
      10                 :            : #include <linux/time.h>
      11                 :            : #include <linux/unistd.h>
      12                 :            : #include <linux/string.h>
      13                 :            : #include <linux/slab.h>
      14                 :            : 
      15                 :            : #include <linux/sunrpc/clnt.h>
      16                 :            : #include <linux/sunrpc/svc.h>
      17                 :            : #include <linux/lockd/lockd.h>
      18                 :            : #include <linux/lockd/share.h>
      19                 :            : 
      20                 :            : static inline int
      21                 :          0 : nlm_cmp_owner(struct nlm_share *share, struct xdr_netobj *oh)
      22                 :            : {
      23                 :          0 :         return share->s_owner.len == oh->len
      24   [ #  #  #  # ]:          0 :             && !memcmp(share->s_owner.data, oh->data, oh->len);
      25                 :            : }
      26                 :            : 
      27                 :            : __be32
      28                 :          0 : nlmsvc_share_file(struct nlm_host *host, struct nlm_file *file,
      29                 :            :                         struct nlm_args *argp)
      30                 :            : {
      31                 :            :         struct nlm_share        *share;
      32                 :          0 :         struct xdr_netobj       *oh = &argp->lock.oh;
      33                 :            :         u8                      *ohdata;
      34                 :            : 
      35         [ #  # ]:          0 :         for (share = file->f_shares; share; share = share->s_next) {
      36   [ #  #  #  # ]:          0 :                 if (share->s_host == host && nlm_cmp_owner(share, oh))
      37                 :            :                         goto update;
      38         [ #  # ]:          0 :                 if ((argp->fsm_access & share->s_mode)
      39         [ #  # ]:          0 :                  || (argp->fsm_mode   & share->s_access ))
      40                 :            :                         return nlm_lck_denied;
      41                 :            :         }
      42                 :            : 
      43                 :          0 :         share = kmalloc(sizeof(*share) + oh->len,
      44                 :            :                                                 GFP_KERNEL);
      45         [ #  # ]:          0 :         if (share == NULL)
      46                 :            :                 return nlm_lck_denied_nolocks;
      47                 :            : 
      48                 :            :         /* Copy owner handle */
      49                 :          0 :         ohdata = (u8 *) (share + 1);
      50                 :          0 :         memcpy(ohdata, oh->data, oh->len);
      51                 :            : 
      52                 :          0 :         share->s_file            = file;
      53                 :          0 :         share->s_host       = host;
      54                 :          0 :         share->s_owner.data = ohdata;
      55                 :          0 :         share->s_owner.len  = oh->len;
      56                 :          0 :         share->s_next       = file->f_shares;
      57                 :          0 :         file->f_shares      = share;
      58                 :            : 
      59                 :            : update:
      60                 :          0 :         share->s_access = argp->fsm_access;
      61                 :          0 :         share->s_mode   = argp->fsm_mode;
      62                 :          0 :         return nlm_granted;
      63                 :            : }
      64                 :            : 
      65                 :            : /*
      66                 :            :  * Delete a share.
      67                 :            :  */
      68                 :            : __be32
      69                 :          0 : nlmsvc_unshare_file(struct nlm_host *host, struct nlm_file *file,
      70                 :            :                         struct nlm_args *argp)
      71                 :            : {
      72                 :            :         struct nlm_share        *share, **shpp;
      73                 :          0 :         struct xdr_netobj       *oh = &argp->lock.oh;
      74                 :            : 
      75         [ #  # ]:          0 :         for (shpp = &file->f_shares; (share = *shpp) != NULL;
      76                 :          0 :                                         shpp = &share->s_next) {
      77   [ #  #  #  # ]:          0 :                 if (share->s_host == host && nlm_cmp_owner(share, oh)) {
      78                 :          0 :                         *shpp = share->s_next;
      79                 :          0 :                         kfree(share);
      80                 :          0 :                         return nlm_granted;
      81                 :            :                 }
      82                 :            :         }
      83                 :            : 
      84                 :            :         /* X/Open spec says return success even if there was no
      85                 :            :          * corresponding share. */
      86                 :            :         return nlm_granted;
      87                 :            : }
      88                 :            : 
      89                 :            : /*
      90                 :            :  * Traverse all shares for a given file, and delete
      91                 :            :  * those owned by the given (type of) host
      92                 :            :  */
      93                 :          0 : void nlmsvc_traverse_shares(struct nlm_host *host, struct nlm_file *file,
      94                 :            :                 nlm_host_match_fn_t match)
      95                 :            : {
      96                 :            :         struct nlm_share        *share, **shpp;
      97                 :            : 
      98                 :          0 :         shpp = &file->f_shares;
      99         [ #  # ]:          0 :         while ((share = *shpp) !=  NULL) {
     100         [ #  # ]:          0 :                 if (match(share->s_host, host)) {
     101                 :          0 :                         *shpp = share->s_next;
     102                 :          0 :                         kfree(share);
     103                 :          0 :                         continue;
     104                 :            :                 }
     105                 :          0 :                 shpp = &share->s_next;
     106                 :            :         }
     107                 :          0 : }

Generated by: LCOV version 1.14