| 1866 | STAILQ_HEAD(lockdesclist, lockdesc); |
| 1867 | |
| 1868 | int |
| 1869 | lf_iteratelocks_sysid(int sysid, lf_iterator *fn, void *arg) |
| 1870 | { |
| 1871 | struct lockf *ls; |
| 1872 | struct lockf_entry *lf; |
| 1873 | struct lockdesc *ldesc; |
| 1874 | struct lockdesclist locks; |
| 1875 | int error; |
| 1876 | |
| 1877 | /* |
| 1878 | * In order to keep the locking simple, we iterate over the |
| 1879 | * active lock lists to build a list of locks that need |
| 1880 | * releasing. We then call the iterator for each one in turn. |
| 1881 | * |
| 1882 | * We take an extra reference to the vnode for the duration to |
| 1883 | * make sure it doesn't go away before we are finished. |
| 1884 | */ |
| 1885 | STAILQ_INIT(&locks); |
| 1886 | sx_xlock(&lf_lock_states_lock); |
| 1887 | LIST_FOREACH(ls, &lf_lock_states, ls_link) { |
| 1888 | sx_xlock(&ls->ls_lock); |
| 1889 | LIST_FOREACH(lf, &ls->ls_active, lf_link) { |
| 1890 | if (lf->lf_owner->lo_sysid != sysid) |
| 1891 | continue; |
| 1892 | |
| 1893 | ldesc = malloc(sizeof(struct lockdesc), M_LOCKF, |
| 1894 | M_WAITOK); |
| 1895 | ldesc->vp = lf->lf_vnode; |
| 1896 | vref(ldesc->vp); |
| 1897 | ldesc->fl.l_start = lf->lf_start; |
| 1898 | if (lf->lf_end == OFF_MAX) |
| 1899 | ldesc->fl.l_len = 0; |
| 1900 | else |
| 1901 | ldesc->fl.l_len = |
| 1902 | lf->lf_end - lf->lf_start + 1; |
| 1903 | ldesc->fl.l_whence = SEEK_SET; |
| 1904 | ldesc->fl.l_type = F_UNLCK; |
| 1905 | ldesc->fl.l_pid = lf->lf_owner->lo_pid; |
| 1906 | ldesc->fl.l_sysid = sysid; |
| 1907 | STAILQ_INSERT_TAIL(&locks, ldesc, link); |
| 1908 | } |
| 1909 | sx_xunlock(&ls->ls_lock); |
| 1910 | } |
| 1911 | sx_xunlock(&lf_lock_states_lock); |
| 1912 | |
| 1913 | /* |
| 1914 | * Call the iterator function for each lock in turn. If the |
| 1915 | * iterator returns an error code, just free the rest of the |
| 1916 | * lockdesc structures. |
| 1917 | */ |
| 1918 | error = 0; |
| 1919 | while ((ldesc = STAILQ_FIRST(&locks)) != NULL) { |
| 1920 | STAILQ_REMOVE_HEAD(&locks, link); |
| 1921 | if (!error) |
| 1922 | error = fn(ldesc->vp, &ldesc->fl, arg); |
| 1923 | vrele(ldesc->vp); |
| 1924 | free(ldesc, M_LOCKF); |
| 1925 | } |
no test coverage detected